by
CMA
- Updated July 10th, 2007
Read the backup guide to find where and how your database has been backed up. The following instructions apply only for databases backed up as .sql dumpfiles. From now on we will assume that the database to be recovered is called my_database.
Verify the last version of the backup: if the backup is not the most recent one you may have lost some data.
Extract from the backup the .sql dump file you are looking for.
Just "in case of", make a backup of the corrupted database if it still exists, for instance:
% tar zcvf /tmp/my_database.tgz /var/lib/mysql/my_database/
Proceed as root.
If the database is used by some web-related stuff, stop the web server
% /etc/init.d/apache stop
Stop the MySQL server
% /etc/init.d/mysql stop
Remove all files in the existing database directory, for instance
% rm /var/lib/mysql/my_database/*
If the database directory is missing because it has been erased, recreate it with the mysql:mysql owner:group, for instance:
% mkdir /var/lib/mysql/my_database; chown mysql:mysql /var/lib/mysql/my_database
Restart MySQL:
% /etc/init.d/mysql start
Recover the database using
% mysql -u root -p<password> my_database < my_database.sql
where <password> is the root password of the MySQL account (ask Fred).
Restart the web server
% /etc/init.d/apache start
And next time think before you click! ;-)