How to Optimize and Repair mySQL database tables

How to check whether mySQL database are corrupted

 

mySQL tables might crash if mySQL service is not shutdown properly. Do the below steps to check whether mySQL database tables are corrupted.

1. Log into your linux server via SSH as root

2. Run the below command to check whether tables are corrupted

mysqlcheck –check DATABASENAME

OR

mysqlcheck -c DATABASENAME

-c, –check = This option check the mySQL table for any errors.

The above command will check all tables in a single mySQL database. Run the below command to check all mySQL databases on the server.

mysqlcheck –check –all-databases

OR

mysqlcheck -c -A

-A, –all-databases means all databases on the server.
 


 

How to optimize mySQL database table

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

2. Run the below command to optimize mySQL databases

mysqlcheck –check DATABASENAME

OR

mysqlcheck -c DATABASENAME

Use ‘-A’ option to optimize all mySQL database tables on the server.

mysqlcheck -o -A

OR

mysqlcheck –optimize –all-databases
 


 

How to Repair mySQL database tables

 
1. Login to linux server via SSH as root

2. Run the below command to repair all corrupted tables in a database

mysqlcheck –repair DATABASENAME

OR

mysqlcheck -r DATABASENAME

‘-A’ option can used with the above command to repair all databases on the server.

mysqlcheck -r -A

OR

mysqlcheck –repair –all-databases