How to Check and Repair MySQL Tables Using Mysqlcheck
When taking mysqldump, it prompts error mysqldump: Got error: 145: Table './mydb/mytable' is marked as crashed and should be repaired when using LOCK TABLES
every time when it encouters a crashed table. and then I have to repair it in order to move ahead. I want to check for all the tables at once instead of one by one.
Answers
-
When your mysql table gets corrupted, use mysqlcheck command to repair it.
Mysqlcheck command checks, repairs, optimizes and analyzes the tables.- Check a Specific Table in a Database
mysqlcheck -c mydb mytable -u root -p Enter password: mydb.mytable OK
- Check All Tables in a Database
mysqlcheck -c mydb -u root -p Enter password: mydb.mytable1 OK mydb.mytable2 OK mydb.mytable3 OK mydb.mytable4 OK ..
- Check All Tables and All Databases
mysqlcheck -c -u root -p --all-databases Enter password: mydb1.mytable1 OK mydb1.mytable2 OK .. mydb2.mytable1 OK mydb2.mytable2 OK
- Additional Useful Mysqlcheck Options
The following are some of the key options that you can use along with mysqlcheck.
-A, –all-databases Consider all the databases
-a, –analyze Analyze tables
-1, –all-in-1 Use one query per database with tables listed in a comma separated way
–auto-repair Repair the table automatically it if is corrupted
-c, –check Check table errors
-C, –check-only-changed Check tables that are changed since last check
-g, –check-upgrade Check for version dependent changes in the tables
-B, –databases Check more than one databases
-F, –fast Check tables that are not closed properly
–fix-db-names Fix DB names
–fix-table-names Fix table names
-f, –force Continue even when there is an error
-e, –extended Perform extended check on a table. This will take a long time to execute.
-m, –medium-check Faster than extended check option, but does most checks
-o, –optimize Optimize tables
-q, –quick Faster than medium check option
-r, –repair Fix the table corruption0
Howdy, Stranger!
Categories
- 94 All Categories
- 20 VoIP
- 7 SIP
- 16 asterisk
- 44 Programming
- 1 Nodejs
- 4 javascript
- 19 PHP
- 8 Codeigniter
- 14 database
- 1 UI/UX
- 2 Flutter
- 28 OS
- 26 Linux
- 1 Virtualization
- 1 Android
- 1 Windows
- 2 legal