Tuesday, March 20, 2012

Repairing Database and Tables

MyISAM was the default storage engine for the MySQL. It is based on the older ISAM code but has many useful extensions. The major deficiency of MyISAM is the absence of transactions support. Versions of MySQL 5.5 and greater have switched to the InnoDB engine to ensure referential integrity constraints, and higher concurrency.

Each MyISAM table is stored on disk in three files. The files have names that begin with the table name and have an extension to indicate the file type. MySQL uses a .frm file to store the definition of the table, but this file is not a part of the MyISAM engine; instead it is a part of the server. The data file has a .MYD (MYData) extension. The index file has a .MYI (MYIndex) extension.

I will now show how to repair the corrupted databases and tables. Usually the mysql files are stored in /var/lib/mysql. Hence navigate your way to the this location.


$ cd /var/lib/mysql
You can find all the databases in the server as folders in this location and enter the folder of the corrupted database.
$ cd db_name
To check and automatically repair all tables
$  myisamchk --silent --force --fast --update-state *.MYI.

If you only want to repair a specific table give the command below:
$ myisamchk -r table_name.MYI

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Affiliate Network Reviews