How to check and repair mySQL database table on a cPanel Server

How to check and repair database table on a cPanel Server


 
You can repair database either through cPanel or from server backend.

I. Steps to repair mySQL database through cPanel

1. Open a web browser and type the below url to access cPanel

https://YourServerIP:2083

OR

https://domain.com:2083

2. Enter cPanel username and Password to login
 

log in cpanel

log in cpanel


3. Click on “MySQL Databases” Under “DATABASES”

cPanel Home >> DATABASES >> MySQL Databases
 
mysql db cpanel
 
4. In the next page you can see two options under “Modify Databases” – Check Database and repair database
 
repair check mysql database
 
Select the database from the dropdown and click on “Check Database” to check the database tables for any issues.

Select the database from the dropdown list and click on “Repair Database” to repair the corrupted database.
 


 
II. How to repair mySQL database from the server backend

1. Log into server via SSH as ‘root’ user

2. Run the below command to check the database for any errors.

mysqlcheck -c [database_name]

OR

mysqlcheck --check [database_name]

OR

User the below command if you have set mySQL root password on the server

mysqlcheck -c [database_name] -u root -p
Enter password:

You will see “OK” result if the tables are fine and you will see “error : Corrupt” if the table is corrupted.
 

Corrupted Tables

Corrupted Tables


 
3. Run the below command to repair corrupted mySQL database tables.

mysqlcheck -r [database_name]

OR

mysqlcheck --repair [database_name]

OR

mysqlcheck -c [database_name] -u root -p

 
4. Try the below command if only one table in the mySQL database is corrupted. The below command is very helpful if the database size is in GBs and you have to repair only single table instead of repairing full database.

root@server [/]# mysqlcheck -c martin_cms content_images
martin_cms.content_images OK

The above command will repair the table ‘content_images’ in the database ‘martin_cms’
 
5. You can run the below command if the database tables are myISAM and the above command didn’t fix the error.

myisamchk -r /var/lib/mysql/[database name]/*.MYI