How to repair MySQL databases and tables on LINUX serversHow to repair MySQL databases and tables on LINUX servers

In this article, we wish to provide you some helpful understandings on ways to repair work MySQL data source and table. This is most likely among one of the most typical, yet troublesome elements you might need to handle regularly. As you understand the MySQL data source is upgraded from time by time. MySQL handles some devices that we could utilize for fixing the data sources and tables.

It’s typical issue that many people deal with, as the data source obtains damaged because of lots of feasible factors such as that it might not obtain brought back correctly, the web server is obtaining rebooted while upgrading data source, to name a few. Right below are a few of the actions you could utilize to repair work the table or the matching data sources by utilizing the mysqlcheck regulate.

To start with, previously doing mysqlcheck we have to take the present MySQL back-up to ensure that if any type of problems happen, we have the ability to go back it back to a much more steady factor. The particular point we ought to think about is that the mysqlcheck commands ought to deal with the data source engine InnoDB.

Change the directory to MySQL as follows,

cd /var/lib/mysql

InnoDB Engines

To use the mysqlcheck for InnoDB engines we must follow the below steps:

 mysqlcheck -c -u root -p --all-databases
 mysqlcheck -c "DATABASE name" -u root -p
#mysqlcheck -c "DATABASE name" "TABLE name" -u root -p

Checks the mentioned tables under the DATABASE name

However, if a MySQL table passes the check it will display an “OK” message for the table.

If the database table has displayed any error means we need to repair the table by the following command:

 mysqlcheck -r "DATABASE name" "Table name" -u root -p

Repair and optimization of tables for all databases

There is a simple command to automatically check, repair and optimize all tables in all databases when running a MySQL server on Linux/Unix/BSD.

 mysqlcheck -u root -p --auto-repair --check --optimize --all-databases

MyISAM Engines

To use the mysqlcheck for MyISAM engines we must follow the below steps

If we are using MyISAM storage engine for MySQL we can use the myisamchk commands to repair the table.

The myisamchk command only works under the database or the tables using MyISAM engines. It will not be work under InnoDB engine.

The mysqlcheck program enables us to check and repair databases while MySQL is running this is useful when we want to work on MySQL without stopping.

Command Steps for checking all the MySQL tables

myisamchk table name

To check all the tables under the database

myisamchk * .MYI

How to repair a table from myisamchk command,

myisamchk --recover "table name"

After the repair, please check for the MySQL repair and confirm whether the issue is fixed.

Conclusion 

The above-mentioned commands will help you troubleshoot the MySQL database and table repair. 

If you need any further support regarding the issue, our server helpdesk support experts are ready to help you, available at your disposal. 

24x7Serversupport Team specialises in Linux server management services such as, cPanel Server Management, Plesk Server Management, Free Panel Server Management, Directadmin Server management and more.  Need help in managing your server? Get Started Now!