{"id":20672,"date":"2020-11-30T04:51:42","date_gmt":"2020-11-29T20:51:42","guid":{"rendered":"https:\/\/web.mwwsb.com.my\/pjci\/?post_type=kb&p=20672"},"modified":"2022-09-08T19:13:43","modified_gmt":"2022-09-08T11:13:43","slug":"how-to-repair-mysql-databases-and-tables","status":"publish","type":"kb","link":"https:\/\/www.casbay.com\/guide\/kb\/how-to-repair-mysql-databases-and-tables","title":{"rendered":"HOW TO: Repair MySQL databases and tables"},"content":{"rendered":"\t\t
In this article, we will guide you to repair MYSQL databases and tables. Please follow the steps below<\/strong>:<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t Before you attempt to repair any database, you should back it up first. To back up all of the files from all of your databases, follow these steps:<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t 1. Log in to your server using SSH.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t 2. Stop the MySQL server using the appropriate command for your Linux distribution:<\/p> 3. Type the following command:<\/p> 4. Restart the MySQL server using the appropriate command for your Linux distribution:<\/p> After you back up your databases, you are ready to start troubleshooting. The\u00a0mysqlcheck<\/em>program enables you to check and repair databases while MySQL is running. This feature is useful when you want to work on a database without stopping the entire MySQL service.<\/p> Additionally,\u00a0mysqlcheck<\/em>\u00a0works on tables that use the MyISAM or InnoDB database engines.<\/p> To use\u00a0mysqlcheck<\/em>, follow these steps:<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t 1. As the root user, type the following command:<\/p> 2. Type the following command, replacing DATABASE<\/em>\u00a0with the name of the database that you want to check:<\/p> The previous command checks all of the tables in the specified database. Alternatively, to check a specific table in a database, type the following command. Replace\u00a0DATABASE<\/em>\u00a0with the name of the database, and replace\u00a0TABLE<\/em>\u00a0with the name of the table that you want to check:<\/p>STEP 1: BACKING UP THE DATABASES<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
service mysqld stop<\/pre><\/li>
service mysql stop<\/pre><\/li><\/ul><\/li><\/ul>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
cp -rfv \/var\/lib\/mysql \/var\/lib\/mysql$(date +%s)<\/pre>
service mysqld start<\/pre><\/li>
service mysql start<\/pre><\/li><\/ul><\/li><\/ul>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
STEP 2: CHECKING AND REPAIRING A TABLE WITH MYSQLCHECK<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
cd \/var\/lib\/mysql<\/pre>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
mysqlcheck DATABASE<\/pre>
mysqlcheck DATABASE TABLE<\/pre><\/div>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t