Use the ALTER TABLE query to rebuild the table using the same storage engine. Repairing MySQL Database with ALTER TABLE The mysqlcheck -r command is the terminal version of the REPAIR TABLE query. Add the -r option to the mysqlcheck command to repair the database table: mysqlcheck -r First, navigate to the MySQL database folder as the root user: cd /var/lib/mysqlĢ. The mysqlcheck command is an alternative to repairing database tables in the terminal.ġ. In normal conditions, a MyISAM table will not result in data loss from using this method. Make sure to do this before performing any other operations on the same table. If the server shuts down during the repair, rerun the REPAIR TABLE operation when the server starts again. Repairing MySQL Database with REPAIR TABLE QueryĪfter scanning and locating the database and the tables with problems, the quickest way to fix the issue is with the REPAIR TABLE query: Follow our guide: How to Back Up & Restore a MySQL Database.īelow you will find three options how to repair a MySQL database. If the database tables are corrupt often, identify the reason for the occurrence.īefore making any changes and starting repairs, create a copy of the directory: cp -rfv /var/lib/mysql /var/lib/mysql_copyĪlternatively, make a backup version of the database before trying any of the repair solutions. However, keep in mind that these methods are not a quick fix and can result in data loss. There are several methods how to repair a database in MySQL. Check the whole database with: mysqlcheck Īlternatively, check a specific table within the database by providing the table name as well: mysqlcheck How to Repair MySQL Database As the root user, navigate to the directory where the databases are stored: sudo suĢ. The program runs in the terminal while the MySQL service is operating. The mysqlcheck command is the command-line version of CHECK TABLE. For example, to do a quick check to find out whether a table closed adequately, run: CHECK TABLE FAST QUICK Īny options that do not apply to the tables are ignored. You can also combine the options for a more detailed check. The FOR UPGRADE and QUICK perform checks on InnoDB engine tables and views while other options are ignored. Without any options, CHECK TABLE performs a MEDIUM check on MyISAM tables and views.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |