{"id":588,"date":"2018-10-17T19:39:30","date_gmt":"2018-10-17T19:39:30","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=588"},"modified":"2018-10-18T14:14:08","modified_gmt":"2018-10-18T14:14:08","slug":"how-to-check-and-repair-myisam-tables-in-mysql","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/17\/how-to-check-and-repair-myisam-tables-in-mysql\/","title":{"rendered":"How To Check And Repair MyISAM Tables In MySQL"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxadmin.io\/wp-content\/uploads\/2017\/11\/repair-myisam-tables-mysql.png\" alt=\"How To Repair MyISAM tables in mysql\" width=\"667\" height=\"311\" \/><\/p>\n<p>MySQL tables can become corrupt for a variety for reasons such as incomplete writes, running out of space, the MySQL daemon being killed or crashing, power failures. If MySQL detects a crashed or corrupt table it will need to be repaired before it can be used again. This guide will walk you through detecting crashed tables and how to repair MyISAM tables.<\/p>\n<h2>Find Crashed MyISAM Tables In MySQL<\/h2>\n<p>Usually a table will show as corrupt in the mysql log, to locate the location of the log, you will be able to find it in my.cnf or you can view it directly in mysql by the following:<\/p>\n<p>MariaDB [(none)]&gt; show variables like &#8216;%log_error%&#8217;;<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br \/>\n| Variable_name | Value |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br \/>\n| log_error | \/var\/lib\/mysql\/centos7-vm2.err |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br \/>\n1 row in set (0.01 sec)<\/p>\n<p>You can then cat that log<\/p>\n<p>cat \/var\/lib\/mysql\/centos7-vm2.err|grep -i crashed<\/p>\n<p>This will return any crashed tables that have been logged. Another way to check all of the tables is to used the mysqlcheck binary<\/p>\n<p>mysqlcheck -A<\/p>\n<p>will check for all crashed tables<\/p>\n<p># mysqlcheck -A<br \/>\nmysql.columns_priv OK<br \/>\nmysql.db OK<br \/>\nmysql.event OK<br \/>\nmysql.func OK<br \/>\nmysql.help_category OK<br \/>\nmysql.help_keyword OK<br \/>\nmysql.help_relation OK<br \/>\nmysql.help_topic OK<br \/>\nmysql.host OK<br \/>\nmysql.ndb_binlog_index OK<br \/>\nmysql.plugin OK<br \/>\nmysql.proc OK<br \/>\nmysql.procs_priv OK<br \/>\nmysql.proxies_priv OK<br \/>\nmysql.servers OK<br \/>\nmysql.tables_priv OK<br \/>\nmysql.time_zone OK<br \/>\nmysql.time_zone_leap_second OK<br \/>\nmysql.time_zone_name OK<br \/>\nmysql.time_zone_transition OK<br \/>\nmysql.time_zone_transition_type OK<br \/>\nmysql.user OK<br \/>\ntest.Persons OK<br \/>\ntest.tablename OK<br \/>\ntest.testtable OK<\/p>\n<p>Lastly you can check a table directly through MySQL as well:<\/p>\n<p>MariaDB [test]&gt; check table testtable;<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+<br \/>\n| Table | Op | Msg_type | Msg_text |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+<br \/>\n| test.testtable | check | status | OK |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+<br \/>\n1 row in set (0.00 sec)<\/p>\n<h2>Repair a single MyISAM table<\/h2>\n<p>Once you have located the table in need of repair you can repair it directly through MySQL. Once connected type \u2018use databasename\u2019 substituting the real database name that contains the crashed table:<\/p>\n<p>MariaDB [(none)]&gt; use test<br \/>\nDatabase changed<\/p>\n<p>After that all you need to do is type \u2018repair table tablename\u2019 substituting \u2018tablename\u2019 with the name of the crashed table:<\/p>\n<p>MariaDB [test]&gt; repair table tablename<br \/>\n-&gt; ;<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+<br \/>\n| Table | Op | Msg_type | Msg_text |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+<br \/>\n| test.tablename | repair | status | OK |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+<br \/>\n1 row in set (0.00 sec)<\/p>\n<h2>Check And Repair All MyISAM Tables<\/h2>\n<p>You can do this quickly by using mysqlcheck with the following command<\/p>\n<p>mysqlcheck -A &#8211;auto-repair<\/p>\n<p>You will see each table followed by a status<\/p>\n<p># mysqlcheck -A &#8211;auto-repair<br \/>\nmysql.columns_priv OK<br \/>\nmysql.db OK<br \/>\nmysql.event OK<br \/>\nmysql.func OK<br \/>\nmysql.help_category OK<br \/>\nmysql.help_keyword OK<br \/>\nmysql.help_relation OK<br \/>\nmysql.help_topic OK<br \/>\nmysql.host OK<br \/>\nmysql.ndb_binlog_index OK<br \/>\nmysql.plugin OK<br \/>\nmysql.proc OK<br \/>\nmysql.procs_priv OK<br \/>\nmysql.proxies_priv OK<br \/>\nmysql.servers OK<br \/>\nmysql.tables_priv OK<br \/>\nmysql.time_zone OK<br \/>\nmysql.time_zone_leap_second OK<br \/>\nmysql.time_zone_name OK<br \/>\nmysql.time_zone_transition OK<br \/>\nmysql.time_zone_transition_type OK<br \/>\nmysql.user OK<br \/>\ntest.Persons OK<br \/>\ntest.tablename OK<br \/>\ntest.testtable OK<\/p>\n<p>This command will attempt to check and repair all MySQL tables in every database on the server. That is it for repairing MyISAM tables in MySQL.<\/p>\n<p>Nov 9, 2017LinuxAdmin.io<\/p>\n<p><a href=\"https:\/\/linuxadmin.io\/repair-myisam-tables-mysql\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>MySQL tables can become corrupt for a variety for reasons such as incomplete writes, running out of space, the MySQL daemon being killed or crashing, power failures. If MySQL detects a crashed or corrupt table it will need to be repaired before it can be used again. This guide will walk you through detecting crashed &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/17\/how-to-check-and-repair-myisam-tables-in-mysql\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How To Check And Repair MyISAM Tables In MySQL&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-588","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/588","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=588"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/588\/revisions"}],"predecessor-version":[{"id":713,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/588\/revisions\/713"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=588"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=588"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=588"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}