{ "created": "2015-12-20T19:56:45Z", "hierarchy": [ { "name": "ROOT", "type": "folder", "uri": "/ROOT" }, { "name": "Repairing a crashed MySQL Table", "type": "article", "uri": "Repairing_a_crashed_MySQL_Table" } ], "html": "\n\n \n \n \n \n \n \n \n \n \n \n \n Repairing a crashed MySQL Table – Nikhil's Personal Wiki\n \n \n \n \n \n
\n
\n \n
\n
\n \n \n\n

Repairing a crashed MySQL Table\n \n

\n

You may be chugging along, doing your thing, logging on to MySQL, and
\nissuing something like this:

\n
mysql> select * from testdatabase.user;\n
\n

Your smile may lose its luster when you’re confronted with this:

\n
ERROR 145 (HY000): Table './testdatabase/user' is marked as crashed and should be repaired\n
\n

Don’t worry. There are a few things you can do to fix this.

\n

When your job is easy

\n

Usually, issuing this should fix the issue:

\n
mysql> repair table testdatabase.user;\n
\n

This, if all goes well, will produce output sort of like this:

\n
+----------------------+--------+----------+------------------------------------------+  \n| Table                | Op     | Msg_type | Msg_text                                 |  \n+----------------------+--------+----------+------------------------------------------+  \n| testdatabase.user    | repair | warning  | Number of rows changed from 0 to 1151697 |  \n| testdatabase.user    | repair | status   | OK                                       |  \n+----------------------+--------+----------+------------------------------------------+  \n2 rows in set (2 min 7.91 sec)\n
\n

When your job gets harder

\n

It gets frustrating when you get something like this:

\n
|------------|--------|----------|-------------------------------------------------------------------------|\n|   Table    |   Op   | Msg_type |                                 Msg_text                                |\n|------------|--------|----------|-------------------------------------------------------------------------|\n| mysql.user | repair | Error    | Table './testdatabase/user' is marked as crashed and should be repaired |\n| mysql.user | repair | Error    | Table 'user' is marked as crashed and should be repaired                |\n| mysql.user | repair | status   | Table is already up to date                                             |\n|------------|--------|----------|-------------------------------------------------------------------------|\n3 rows in set (0.00 sec)\n
\n

DON’T PANIC. This can be fixed by quitting MySQL, and doing this:

\n
cd /var/lib/mysql/testdatabase  \nmyisamchk --safe-recover user\n
\n

user, of course, is the table you wanted to recover. If the Gods have
\nmercy, you will see something like this:

\n
Warning: option 'key_buffer_size': unsigned value 18446744073709551615 adjusted to 4294963200  \nWarning: option 'read_buffer_size': unsigned value 18446744073709551615 adjusted to 4294967295  \nWarning: option 'write_buffer_size': unsigned value 18446744073709551615 adjusted to 4294967295  \nWarning: option 'sort_buffer_size': unsigned value 18446744073709551615 adjusted to 4294967295  \n- recovering (with keycache) MyISAM-table 'user'  \nData records: 81  \nDuplicate key  1 for record at       7918 against new record at       3959  \nDuplicate key  1 for record at       8132 against new record at       3638  \nDuplicate key  1 for record at       8239 against new record at       1498  \nDuplicate key  1 for record at       8560 against new record at       4280  \nData records: 77  \nmyisamchk: warning: 4 records have been removed\n
\n

Ta da! Assuming, of course, that your table’s the default MyISAM type.

\n\n\n
\n \n
\n \n \n \n \n \n\n", "id": "7228dba7-5bf8-598a-92e8-d8479dedae6d", "modified": "2024-04-15T23:13:03Z", "revisions": [ { "authorEmail": "mail@nikhil.io", "authorName": "Nikhil Anand", "date": "2024-04-15T23:13:03Z", "id": "1f343266dce411121f0cff3ca7e3e0632be6ce97", "shortId": "1f343266", "subject": "Some more notes\n", "content": "You may be chugging along, doing your thing, logging on to MySQL, and\nissuing something like this:\n\n mysql> select * from testdatabase.user;\n\nYour smile may lose its luster when you're confronted with this:\n\n ERROR 145 (HY000): Table './testdatabase/user' is marked as crashed and should be repaired\n\nDon't worry. There are a few things you can do to fix this.\n\n### When your job is easy\n\nUsually, issuing this should fix the issue:\n\n mysql> repair table testdatabase.user;\n\nThis, if all goes well, will produce output sort of like this:\n\n +----------------------+--------+----------+------------------------------------------+ \n | Table                | Op     | Msg_type | Msg_text                                 | \n +----------------------+--------+----------+------------------------------------------+ \n | testdatabase.user    | repair | warning  | Number of rows changed from 0 to 1151697 | \n | testdatabase.user    | repair | status   | OK                                       | \n +----------------------+--------+----------+------------------------------------------+ \n 2 rows in set (2 min 7.91 sec)\n\n### When your job gets harder\n\nIt gets frustrating when you get something like this:\n\n |------------|--------|----------|-------------------------------------------------------------------------|\n | Table | Op | Msg_type | Msg_text |\n |------------|--------|----------|-------------------------------------------------------------------------|\n | mysql.user | repair | Error | Table './testdatabase/user' is marked as crashed and should be repaired |\n | mysql.user | repair | Error | Table 'user' is marked as crashed and should be repaired |\n | mysql.user | repair | status | Table is already up to date |\n |------------|--------|----------|-------------------------------------------------------------------------|\n 3 rows in set (0.00 sec)\n\nDON'T PANIC. This can be fixed by quitting MySQL, and doing this:\n\n cd /var/lib/mysql/testdatabase \n myisamchk --safe-recover user\n\n`user`, of course, is the table you wanted to recover. If the Gods have\nmercy, you will see something like this:\n\n Warning: option 'key_buffer_size': unsigned value 18446744073709551615 adjusted to 4294963200 \n Warning: option 'read_buffer_size': unsigned value 18446744073709551615 adjusted to 4294967295 \n Warning: option 'write_buffer_size': unsigned value 18446744073709551615 adjusted to 4294967295 \n Warning: option 'sort_buffer_size': unsigned value 18446744073709551615 adjusted to 4294967295 \n - recovering (with keycache) MyISAM-table 'user' \n Data records: 81 \n Duplicate key  1 for record at       7918 against new record at       3959 \n Duplicate key  1 for record at       8132 against new record at       3638 \n Duplicate key  1 for record at       8239 against new record at       1498 \n Duplicate key  1 for record at       8560 against new record at       4280 \n Data records: 77 \n myisamchk: warning: 4 records have been removed\n\nTa da! Assuming, of course, that your table's the default MyISAM type.\n" }, { "authorEmail": "mail@nikhil.io", "authorName": "Nikhil Anand", "date": "2015-12-27T07:27:56Z", "id": "5a5b1a32f41081d062ab86f8869a961bcad79668", "shortId": "5a5b1a32", "subject": "Fix Markdown conversion\n\nSaw half a season of The Office\n", "content": "You may be chugging along, doing your thing, logging on to MySQL, and\nissuing something like this:\n\n mysql> select * from testdatabase.user;\n\nYour smile may lose its luster when you're confronted with this:\n\n ERROR 145 (HY000): Table './testdatabase/user' is marked as crashed and should be repaired\n\nDon't worry. There are a few things you can do to fix this.\n\n### When your job is easy\n\nUsually, issuing this should fix the issue:\n\n mysql> repair table testdatabase.user;\n\nThis, if all goes well, will produce output sort of like this:\n\n +----------------------+--------+----------+------------------------------------------+ \n | Table                | Op     | Msg_type | Msg_text                                 | \n +----------------------+--------+----------+------------------------------------------+ \n | testdatabase.user    | repair | warning  | Number of rows changed from 0 to 1151697 | \n | testdatabase.user    | repair | status   | OK                                       | \n +----------------------+--------+----------+------------------------------------------+ \n 2 rows in set (2 min 7.91 sec)\n\n### When your job gets harder\n\nIt gets frustrating when you get something like this:\n\n |------------|--------|----------|-------------------------------------------------------------------------|\n | Table | Op | Msg_type | Msg_text |\n |------------|--------|----------|-------------------------------------------------------------------------|\n | mysql.user | repair | Error | Table './testdatabase/user' is marked as crashed and should be repaired |\n | mysql.user | repair | Error | Table 'user' is marked as crashed and should be repaired |\n | mysql.user | repair | status | Table is already up to date |\n |------------|--------|----------|-------------------------------------------------------------------------|\n 3 rows in set (0.00 sec)\n\nDON'T PANIC. This can be fixed by quitting MySQL, and doing this:\n\n cd /var/lib/mysql/testdatabase \n myisamchk --safe-recover user\n\n`user`, of course, is the table you wanted to recover. If the Gods have\nmercy, you will see something like this:\n\n Warning: option 'key_buffer_size': unsigned value 18446744073709551615 adjusted to 4294963200 \n Warning: option 'read_buffer_size': unsigned value 18446744073709551615 adjusted to 4294967295 \n Warning: option 'write_buffer_size': unsigned value 18446744073709551615 adjusted to 4294967295 \n Warning: option 'sort_buffer_size': unsigned value 18446744073709551615 adjusted to 4294967295 \n - recovering (with keycache) MyISAM-table 'user' \n Data records: 81 \n Duplicate key  1 for record at       7918 against new record at       3959 \n Duplicate key  1 for record at       8132 against new record at       3638 \n Duplicate key  1 for record at       8239 against new record at       1498 \n Duplicate key  1 for record at       8560 against new record at       4280 \n Data records: 77 \n myisamchk: warning: 4 records have been removed\n\nTa da! Assuming, of course, that your table's the default MyISAM type.\n" }, { "authorEmail": "mail@nikhil.io", "authorName": "Nikhil Anand", "date": "2015-12-21T02:30:47Z", "id": "3f2c54b1d767218fcb4855fbac306b015afaf551", "shortId": "3f2c54b1", "subject": "Incremental\n", "content": "You may be chugging along, doing your thing, logging on to MySQL, and\nissuing something like this:\n\n` mysql> select * from testdatabase.user;`\n\nYour smile may lose its luster when you're confronted with this:\n\n`   ERROR 145 (HY000): Table './testdatabase/user' is marked as crashed and should be repaired`\n\nDon't worry. There are a few things you can do to fix this.\n\n### When your job is easy\n\nUsually, issuing this should fix the issue:\n\n` mysql> repair table testdatabase.user;`\n\nThis, if all goes well, will produce output sort of like this:\n\n` +----------------------+--------+----------+------------------------------------------+` \n` | Table                | Op     | Msg_type | Msg_text                                 |` \n` +----------------------+--------+----------+------------------------------------------+` \n` | testdatabase.user    | repair | warning  | Number of rows changed from 0 to 1151697 |` \n` | testdatabase.user    | repair | status   | OK                                       |` \n` +----------------------+--------+----------+------------------------------------------+` \n` 2 rows in set (2 min 7.91 sec)`\n\n### When your job gets harder\n\nIt gets frustrating when you get something like this:\n\n` +------------+--------+----------+------------------------------------------------------------------+` \n` | Table      | Op     | Msg_type | Msg_text                                                         |` \n` +------------+--------+----------+------------------------------------------------------------------+` \n` | mysql.user | repair | Error    | Table './testdatabase/user' is marked as crashed and should be repaired | ` \n` | mysql.user | repair | Error    | Table 'user' is marked as crashed and should be repaired         | ` \n` | mysql.user | repair | status   | Table is already up to date                                      | ` \n` +------------+--------+----------+------------------------------------------------------------------+` \n` 3 rows in set (0.00 sec)`\n\nDON'T PANIC. This can be fixed by quitting MySQL, and doing this:\n\n` cd /var/lib/mysql/testdatabase` \n` myisamchk --safe-recover user`\n\n\"user\", of course, is the table you wanted to recover. If the Gods have\nmercy, you will see something like this:\n\n` Warning: option 'key_buffer_size': unsigned value 18446744073709551615 adjusted to 4294963200` \n` Warning: option 'read_buffer_size': unsigned value 18446744073709551615 adjusted to 4294967295` \n` Warning: option 'write_buffer_size': unsigned value 18446744073709551615 adjusted to 4294967295` \n` Warning: option 'sort_buffer_size': unsigned value 18446744073709551615 adjusted to 4294967295` \n` - recovering (with keycache) MyISAM-table 'user'` \n` Data records: 81` \n` Duplicate key  1 for record at       7918 against new record at       3959` \n` Duplicate key  1 for record at       8132 against new record at       3638` \n` Duplicate key  1 for record at       8239 against new record at       1498` \n` Duplicate key  1 for record at       8560 against new record at       4280` \n` Data records: 77` \n` myisamchk: warning: 4 records have been removed`\n\nTa da! Assuming, of course, that your table's the default MyISAM type.\n" }, { "authorEmail": "mail@nikhil.io", "authorName": "Nikhil Anand", "date": "2015-12-20T19:56:45Z", "id": "1d503bbfd09e978ad799ada6187c8b2cdd0e53a1", "shortId": "1d503bbf", "subject": "Repairing a crashed MySQL Table : First Draft", "content": "You may be chugging along, doing your thing, logging on to MySQL, and\nissuing something like this:\n\n` mysql> select * from testdatabase.user;`\n\nYour smile may lose its luster when you're confronted with this:\n\n`   ERROR 145 (HY000): Table './testdatabase/user' is marked as crashed and should be repaired`\n\nDon't worry. There are a few things you can do to fix this.\n\n### When your job is easy\n\nUsually, issuing this should fix the issue:\n\n` mysql> repair table testdatabase.user;`\n\nThis, if all goes well, will produce output sort of like this:\n\n` +----------------------+--------+----------+------------------------------------------+` \n` | Table                | Op     | Msg_type | Msg_text                                 |` \n` +----------------------+--------+----------+------------------------------------------+` \n` | testdatabase.user    | repair | warning  | Number of rows changed from 0 to 1151697 |` \n` | testdatabase.user    | repair | status   | OK                                       |` \n` +----------------------+--------+----------+------------------------------------------+` \n` 2 rows in set (2 min 7.91 sec)`\n\n### When your job gets harder\n\nIt gets frustrating when you get something like this:\n\n` +------------+--------+----------+------------------------------------------------------------------+` \n` | Table      | Op     | Msg_type | Msg_text                                                         |` \n` +------------+--------+----------+------------------------------------------------------------------+` \n` | mysql.user | repair | Error    | Table './testdatabase/user' is marked as crashed and should be repaired | ` \n` | mysql.user | repair | Error    | Table 'user' is marked as crashed and should be repaired         | ` \n` | mysql.user | repair | status   | Table is already up to date                                      | ` \n` +------------+--------+----------+------------------------------------------------------------------+` \n` 3 rows in set (0.00 sec)`\n\nDON'T PANIC. This can be fixed by quitting MySQL, and doing this:\n\n` cd /var/lib/mysql/testdatabase` \n` myisamchk --safe-recover user`\n\n\"user\", of course, is the table you wanted to recover. If the Gods have\nmercy, you will see something like this:\n\n` Warning: option 'key_buffer_size': unsigned value 18446744073709551615 adjusted to 4294963200` \n` Warning: option 'read_buffer_size': unsigned value 18446744073709551615 adjusted to 4294967295` \n` Warning: option 'write_buffer_size': unsigned value 18446744073709551615 adjusted to 4294967295` \n` Warning: option 'sort_buffer_size': unsigned value 18446744073709551615 adjusted to 4294967295` \n` - recovering (with keycache) MyISAM-table 'user'` \n` Data records: 81` \n` Duplicate key  1 for record at       7918 against new record at       3959` \n` Duplicate key  1 for record at       8132 against new record at       3638` \n` Duplicate key  1 for record at       8239 against new record at       1498` \n` Duplicate key  1 for record at       8560 against new record at       4280` \n` Data records: 77` \n` myisamchk: warning: 4 records have been removed`\n\nTa da! Assuming, of course, that your table's the default MyISAM type.\n\n[Category:Nikhil's Notes](Category:Nikhil's_Notes \"wikilink\")\n[Category:From a past sysadmin\nlife](Category:From_a_past_sysadmin_life \"wikilink\")\n" } ], "sizeInBytes": 3590, "source": "You may be chugging along, doing your thing, logging on to MySQL, and\nissuing something like this:\n\n mysql> select * from testdatabase.user;\n\nYour smile may lose its luster when you're confronted with this:\n\n ERROR 145 (HY000): Table './testdatabase/user' is marked as crashed and should be repaired\n\nDon't worry. There are a few things you can do to fix this.\n\n### When your job is easy\n\nUsually, issuing this should fix the issue:\n\n mysql> repair table testdatabase.user;\n\nThis, if all goes well, will produce output sort of like this:\n\n +----------------------+--------+----------+------------------------------------------+ \n | Table                | Op     | Msg_type | Msg_text                                 | \n +----------------------+--------+----------+------------------------------------------+ \n | testdatabase.user    | repair | warning  | Number of rows changed from 0 to 1151697 | \n | testdatabase.user    | repair | status   | OK                                       | \n +----------------------+--------+----------+------------------------------------------+ \n 2 rows in set (2 min 7.91 sec)\n\n### When your job gets harder\n\nIt gets frustrating when you get something like this:\n\n |------------|--------|----------|-------------------------------------------------------------------------|\n | Table | Op | Msg_type | Msg_text |\n |------------|--------|----------|-------------------------------------------------------------------------|\n | mysql.user | repair | Error | Table './testdatabase/user' is marked as crashed and should be repaired |\n | mysql.user | repair | Error | Table 'user' is marked as crashed and should be repaired |\n | mysql.user | repair | status | Table is already up to date |\n |------------|--------|----------|-------------------------------------------------------------------------|\n 3 rows in set (0.00 sec)\n\nDON'T PANIC. This can be fixed by quitting MySQL, and doing this:\n\n cd /var/lib/mysql/testdatabase \n myisamchk --safe-recover user\n\n`user`, of course, is the table you wanted to recover. If the Gods have\nmercy, you will see something like this:\n\n Warning: option 'key_buffer_size': unsigned value 18446744073709551615 adjusted to 4294963200 \n Warning: option 'read_buffer_size': unsigned value 18446744073709551615 adjusted to 4294967295 \n Warning: option 'write_buffer_size': unsigned value 18446744073709551615 adjusted to 4294967295 \n Warning: option 'sort_buffer_size': unsigned value 18446744073709551615 adjusted to 4294967295 \n - recovering (with keycache) MyISAM-table 'user' \n Data records: 81 \n Duplicate key  1 for record at       7918 against new record at       3959 \n Duplicate key  1 for record at       8132 against new record at       3638 \n Duplicate key  1 for record at       8239 against new record at       1498 \n Duplicate key  1 for record at       8560 against new record at       4280 \n Data records: 77 \n myisamchk: warning: 4 records have been removed\n\nTa da! Assuming, of course, that your table's the default MyISAM type.\n", "title": "Repairing a crashed MySQL Table", "untracked": false, "uri": "/Repairing_a_crashed_MySQL_Table", "relativePath": "Repairing a crashed MySQL Table.md" }