Monday, June 27, 2011

MySQL: Check, repair and optimize tables (all tables, all databases)

MySQL check, repair or optimize:
- all tables in a databases
- all tables from all databases
- a certain table

Check tables for all databases:
$ mysqlcheck -u root -p -v --all-databases

Check tables for a certain database:
$ mysqlcheck -u root -p -v db_name

Optimize table:
$ mysqlcheck -u root -p -v --optimize db_name table_name

Repair table:
$ mysqlcheck -u root -p -v --repair db_name table_name

Auto-repair tables:
$ mysqlcheck -u root -p -v --auto-repair db_name

1 comment:

Raj said...

Most of the database administrators recommend that restore corrupt mysql database from updated backup before repair. If you don’t have any updated backup then repair corrupt MySQL database.