Repair Database Table via Terminal

jmsgrady
New Contributor III

It's taking forever to repair the Database Tables, and I'm not certain the process continues after I'm timed out of the web interface. Is it possible to repair the database tables from the command line?

1 ACCEPTED SOLUTION

Sonic84
Contributor III

You can use the mysqlcheck command to perform several operations including check, repair and/or optimize.

example:
mysqlcheck -u root -p --auto-repair --check --optimize --all-databases
http://dev.mysql.com/doc/refman/5.0/en/mysqlcheck.html

View solution in original post

5 REPLIES 5

Sonic84
Contributor III

You can use the mysqlcheck command to perform several operations including check, repair and/or optimize.

example:
mysqlcheck -u root -p --auto-repair --check --optimize --all-databases
http://dev.mysql.com/doc/refman/5.0/en/mysqlcheck.html

jmsgrady
New Contributor III

Thanks Sonic84!

tchung
New Contributor

How to auto repair all databases with mysqlcheck

$ mysqlcheck -u root --auto-repair --all-databases
--auto-repair If a checked table is corrupted, automatically fix it. Repairing will be done after all tables have been checked, if corrupted ones were found.
--all-databases Check all the databases. This is the same as --databases with all databases selected.

donmontalvo
Esteemed Contributor III

Thought I'd post these commands here, in case anyone needs to first do a full backup of MySQL, then check and repair all databases.

First command does a full backup of MySQL, this includes all databases, all GRANTs, etc.
Second command outputs a log so you can peruse table maintenance success, since Command Prompt on Windows doesn't seem to let you scroll up through the whole enchilada output.

mysqldump -u root -p<password> --all-databases > database_backup.sql
mysqlcheck -u root -p<password> --auto-repair --check --all-databases > database_backup.txt
--
https://donmontalvo.com

mpebley
New Contributor III

removed -wrong posting