How to Repair MySQL Database

MySQL is the most popular relational database management system. Many WEB applications use the MySQL database. In the actual use process, the MySQL database is backed up regularly at the end, because whether it is a program or a system environment problem, the database may be damaged. Example: Table XXX is marked as crashed and should be repaired.

When encountering a corrupted MySQL database, if there is no backup to replace, you can try to repair it.

Repair using phpMyAdmin (a famous web-side MySQL management tool)

The best environment to install phpMyAdmin is lamp (Linux + Apache + MySQL/MariaDB + PHP) or lnmp ((Linux + Nginx + MySQL/MariaDB + PHP), download phpMyAdmin on the official website and install it, it is very simple, and the installation is not described here Process.

After logging in to phpMyAdmin, click on the database that needs to be repaired on the left. All tables in the database will be listed on the right, select the damaged table or pull the page to the bottom, click Select All, and select Repair in the drop-down box.

phpMyAdmin repair table

Repair MySQL database in command mode

After logging in to the MySQL server (for example, the Linux system server SSH login server is directly executed)

Repair a single database: mysqlcheck -r -u database username -p password database name 

Example: mysqlcheck -r -udemo -pdemo demo

If the database system table is damaged and cannot be started, you can use the following methods to repair:

Enter the following command on the Linux system:

myisamchk -r -f /mysql/var/mysql/*.MYI

Windows system enter the following command:

myisamchk -r -f D:\mysql\data\mysql\*.MYI

Note to replace the above path with the actual path.

Leave a Comment