UnixServerAdmin

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.

Advertisements

February 8, 2011 - Posted by | MySQL | ,

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: