How to repair MySQL table from SSH


March 28th, 2009

If you are getting an MySQL related error on your site for any database, you can repair the database through SSH from MySQL prompt.

For example:

Invalid SQL: SELECT * FROM `something` WHERE `id` = '151' ORDER BY `someid` ASC LIMIT 0,20; (Can't open file: 'sometable.MYI' (errno: 145))

Login to your server as root.

Firstly check the status of MySQL on your dedicated server. Normally, it should be ok – as you’re getting this error.

The database table can be repaired only if the Mysql server is in running status. You can check the status by the command.

root# /etc/init.d/myssql status

Now, login to the MySQL database for a required user.

mysql> mysql –u databaseusername –p database password databasename

You need to select that particular database having problem.

mysql> use databasename;

Now, you will have to check whether the table is corrupted. On giving the below command you will get a NULL value as your output if it is   corrupted otherwise it’s alright.

mysql> check table tablename;

If the table is corrupted for that particular database, then you need
to repair the table by giving the following command.

mysql> repair table tablename;

This will repair the table for you.
This article is released by SupportFacility.Com — the leaders in providing outsourced technical support, live chat support & help desk support for web hosts. Interested ? Opt for a trial now.


2 Comments »

  1. There is one software which can help when your MySQL database files get corrupted. You can go for Stellar Phoenix Database Recovery For MySQL Software. MySQL repair software can recover MySQL database files. It supports MySQL .myd and .myi files. You can try demo version of this software to check whether your files are recoverable or not.

    Comment by David — June 15, 2009 @ 4:45 pm

  2. To repair the database tables:
    mysqlcheck -r [DBNAME]

    Comment by onel0ve — February 17, 2011 @ 10:35 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment