G
G
Gleb Igumnov2011-11-21 16:07:43
PHP
Gleb Igumnov, 2011-11-21 16:07:43

Fixing Duplicate Keys in a Database Using PHP

Given : there is a MySQL database, a forum is spinning on it. It has been spinning for a long time, no one updated the forum engine, so duplicate keys appeared in the database, which makes it impossible to automatically convert the forum to another engine. The database is rather big (uncompressed dump 200 MB), I really don't want to edit the handles, in addition:
Not given : phpmyadmin, cpanel, ssh or any other intelligible way to work with the database, only ftp and the ability to run php scripts.
Question: Is there a way to fix the database from duplicate keys in such conditions that is not associated with a bunch of hemorrhoids and small manual work?
Forum XMB

Answer the question

In order to leave comments, you need to log in

4 answer(s)
E
edogs, 2011-11-21
@edogs

One of the simplest - we hang a unique key forcibly, and demolish it.
ALTER IGNORE TABLE `backup` ADD UNIQUE( `title`);
ALTER TABLE `backup` DROP KEY `title`;

G
Gleb Igumnov, 2011-11-21
@CrazySage

In general, the second question - does anyone know which version of PhpMyAdmin still worked with PHP4? Not to go over everything :)

E
Evengard, 2011-11-21
@Evengard

Try playing around with LIMIT 1.1. If it doesn’t return anything, then there is no duplicate key, if it returns, it’s already there, you will have to fix it.

H
Hint, 2011-11-21
@Hint

SELECT id, COUNT(*) AS cnt FROM table GROUP BY id HAVING cnt > 1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question