Thursday, January 20, 2011

How to restore a table from backup in mysql

>DROP TABLE IF EXISTS `db.users`;
>CREATE TABLE `db.users` SELECT * FROM `db2.users`;


To do this you have to use:

>CREATE TABLE db.users LIKE db2.users;

then you populate it with the data from the old table with:

>INSERT INTO db.users SELECT * FROM db2.users;

If the copied old table has many keys then it may help to speed the INSERT if you turn off the keys using the following before the INSERT:

>ALTER TABLE db.users DISABLE KEYS;

And then after the INSERT:

>ALTER TABLE db.users ENABLE KEYS;