How to repair corrupted mysql database

Sometimes it happens that your database get corrupted due to many reason like it does not get restored properly or server get rebooted while updating database etc…. You can repair the database through either cpanel or SSH.

cPanel

Go to cpanel -> mysql databases -> select database which you required to repair.

Login to server with root access

check your mysql database

/usr/bin/mysqlcheck <database>

/usr/bin/mysqlcheck –auto-repair –check –optimize –all-databases

Stop mysql using following command

/etc/init.d/mysql stop

Run following command to check all teh tables in the database

/usr/bin/myisamchk /var/lib/mysql/databasename/*.MYI

Run following command to repair all teh tables in the database

/usr/bin/myisamchk -r /var/lib/mysql/databasename/*.MYI

Then recheck again using following command

/usr/bin/myisamchk /var/lib/mysql/databasename/*.MYI

Restrart MySql service using following command

/etc/init.d/mysql restart

The following are some of the key options that you can use along with mysqlcheck.

-A, –all-databases Consider all the databases
-a, –analyze Analyze tables
-1, –all-in-1 Use one query per database with tables listed in a comma separated way
–auto-repair Repair the table automatically it if is corrupted
-c, –check Check table errors
-C, –check-only-changed Check tables that are changed since last check
-g, –check-upgrade Check for version dependent changes in the tables
-B, –databases Check more than one databases
-F, –fast Check tables that are not closed properly
–fix-db-names Fix DB names
–fix-table-names Fix table names
-f, –force Continue even when there is an error
-e, –extended Perform extended check on a table. This will take a long time to execute.
-m, –medium-check Faster than extended check option, but does most checks
-o, –optimize Optimize tables
-q, –quick Faster than medium check option
-r, –repair Fix the table corruption
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Replace MySQL with MariaDB in cPanel

MariaDB strives to be the logical choice for database professionals looking for a robust,...

Test MySQL database connection with php script

You can use the following php script which is used to test mysql database connection on your...

cPanel Log file locations

cPanel log file locations and Basic troubleshooting, most activity that happens on a server to...

MySQL downgrade on cPanel server

You know downgrades are not recommended, it’s always best to stick with a newer version and work...

Powered by WHMCompleteSolution