It seems that a *.sql file I recently imported had use mysql instead of use dbname. Now the mysql database contains a large number of tables which don't belong there.

Is there an easy/efficient way to clean this up?

Note: I am using MariaDB, but I think a generic answer would be more useful for others.

mysql Ver 15.1 Distrib 10.1.10-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2


No clean way...

USE MyDatabase;
RENAME TABLE mysql.mytable1 TO mytable1;
RENAME TABLE mysql.mytable2 TO mytable2;


You said "large number"... You could get the list thus:

    FROM information_schema.TABLES
    WHERE schema_name = 'mysql';

But be very careful not to rename the system tables!

| improve this answer | |
  • Ok.. Where could I find a list of the "correct" tables in the mysql database? – donquixote Jan 20 '16 at 11:02
  • 1
    @donquixote: The mysql Database Tables - MariaDB Knowledge Base (no idea if that list is exhaustive, though – looks like it should be but I'm not sure) – Andriy M Jan 20 '16 at 12:45
  • @donquixote you could also grep for them in your most recent backup file from before the mistake was made. – Michael - sqlbot Jan 20 '16 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.