﻿{"id":1840,"date":"2019-04-12T00:51:04","date_gmt":"2019-04-11T16:51:04","guid":{"rendered":"http:\/\/nick.txtcc.com\/?p=1840"},"modified":"2019-04-12T01:52:36","modified_gmt":"2019-04-11T17:52:36","slug":"mysql-error-table-is-marked-as-crashed-and-should-be-repaired","status":"publish","type":"post","link":"http:\/\/nick.txtcc.com\/index.php\/linux\/1840","title":{"rendered":"MySQL error: table is marked as crashed and should be repaired"},"content":{"rendered":"<p>You may experience crashed\u00a0<strong>MyISAM tables<\/strong>\u00a0in MySQL from times to times, especially after a forced shutdown (<code>kill -9<\/code>) of MySQL or a crash of the entire server.<span id=\"more-3643\"><\/span><\/p>\n<p>The errors will look like this in your logs. InnoDB has good crash recovery on its own and will probably never give you these errors as it self-repairs upon MySQL restart.<\/p>\n<pre>[ERROR] \/usr\/libexec\/mysqld: Table '.\/dbname\/table_name' is marked as crashed and should be repaired\n[ERROR] \/usr\/libexec\/mysqld: Table '.\/dbname\/table_name' is marked as crashed and should be repaired\n[ERROR] \/usr\/libexec\/mysqld: Table '.\/dbname\/table_name' is marked as crashed and should be repaired<\/pre>\n<p>You can also find broken tables with the\u00a0<strong>myisamchk<\/strong>\u00a0tool that is provided by the MySQL server installation.<\/p>\n<pre># myisamchk -s \/var\/lib\/mysql\/*\/*.MYI\nMyISAM-table '\/var\/lib\/mysql\/dbname\/table_name.MYI' is marked as crashed and should be repaired<\/pre>\n<p>The above command will show you each table that is in need of repair.<\/p>\n<p>If a table is reported as damaged, repair it with that same tool.<\/p>\n<pre># myisamchk -r \/var\/lib\/mysql\/dbname\/table_name.MYI<\/pre>\n<p>That solves the problem in most cases. If it doesn&#8217;t, make sure to stop your webservice (so no new MySQL requests are being made), stop the MySQLd daemon itself and run the following command.<\/p>\n<pre># myisamchk -r --update-state \/var\/lib\/mysql\/dbname\/table_name.MYI<\/pre>\n<p>The\u00a0<code>--update-state<\/code>\u00a0tells MySQL to mark the table as &#8220;checked&#8221;. Restart your MySQLd and webservice and you should be good go to.<\/p>\n<p>If you&#8217;re up for more mild reading, have a look at the good documentation of MySQL itself on\u00a0<a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/myisam-repair.html\">MyISAM repairs<\/a>.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Try running the following query:<\/p>\n<pre class=\"lang-sql prettyprint prettyprinted\"><code>&lt;span class=&quot;pln&quot;&gt;repair &lt;\/span&gt;\n&lt;span class=&quot;kwd&quot;&gt;table&lt;\/span&gt; &lt;span class=&quot;pun&quot;&gt;&lt;&lt;\/span&gt;\n&lt;span class=&quot;pln&quot;&gt;table_name&lt;\/span&gt;\n&lt;span class=&quot;pun&quot;&gt;&gt;;\n\nmysqlcheck -r --all-databases -u root -p\n\n&lt;\/span&gt;<\/code><\/pre>","protected":false},"excerpt":{"rendered":"<p>You may experience crashed\u00a0MyISAM tables\u00a0in MySQL from times to times, especially after a forced shu&#46;&#46;&#46;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,101],"tags":[],"class_list":["post-1840","post","type-post","status-publish","format-standard","hentry","category-linux","category-db"],"_links":{"self":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/1840","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/comments?post=1840"}],"version-history":[{"count":3,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/1840\/revisions"}],"predecessor-version":[{"id":1843,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/1840\/revisions\/1843"}],"wp:attachment":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/media?parent=1840"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/categories?post=1840"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/tags?post=1840"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}