Tuesday, 27 January 2009

Repair a MySQL database or table - Linux

You have a MySQL database that needs to be repaired. There are a couple of ways you can do this. It is ideal to do these while mysqld is not running.

The first way is to use mysqlcheck

mysqlcheck -oCvf --auto-repair 


The next way is it use myisamchk. Myisamchk is used only to repair myisam tables so you would need to be within the database directory to run this command on .MYI files.

cd /var/lib/mysql/
myisamchk -r -q *MYI


If you know what table needs to be repaired then you can use myisamchk and repair just that .MYI file or you can use mysql directly. This of course will be done while mysqld is running.

mysql -uroot -p 
mysql> repair table ;


Please use these at your own discretion. We take no responsibility for data loss

No comments:

Post a Comment