Server Administration & Management

How to repair corrupt database

I had a very serious problem my database tables were corrupted. When I repaired my database from cpanel >> mysql >> repair database it showed that database has been repaired but few tables are corrupted.

To fix the issue I ssh to my server. and performed following operations.

First stop mysql service
# /etc/init.d/mysql stop

1) I run this to check all tables in the database
# /usr/bin/myisamchk /var/lib/mysql/databasename/*.MYI

2) Now repair all tables in database
# /usr/bin/myisamchk -r /var/lib/mysql/databasename/*.MYI

3) After repaired i rerun the check
# /usr/bin/myisamchk /var/lib/mysql/databasename/*.MYI

4) Restart mysql service
# /etc/init.d/mysql restart


Or you can simply use mysqlcheck feature.

Check database

# mysqlcheck database_name

Repair database

# mysqlcheck -r database_name

This fixed my issue.

February 8, 2011 Posted by | MySQL | , | Leave a comment