{"id":361,"date":"2015-05-28T13:23:22","date_gmt":"2015-05-28T13:23:22","guid":{"rendered":"http:\/\/kb.veeble.org\/?p=361"},"modified":"2025-03-25T12:48:13","modified_gmt":"2025-03-25T07:18:13","slug":"recover-corrupted-table-mysql","status":"publish","type":"post","link":"https:\/\/www.veeble.com\/kb\/recover-corrupted-table-mysql\/","title":{"rendered":"How to recover Corrupted Table [MySql]"},"content":{"rendered":"\n<p>Why does the database crash!? What can we do if it does? Database corruption can be due to many scenarios, like when a query does not find a table where it&#8217;s supposed to or when the query comes back with incorrect data.<\/p>\n\n\n\n<p>They &nbsp;can get corrupted due to a variety of reasons, &nbsp;we can identify the errors from the relevant logs files, and you may find some entries like this,<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span style=\"color: #bd4848;\"><span style=\"font-family: Consolas, 'Andale Mono', Courier, 'Courier New', monospace;\"><span style=\"font-size: small;\">Incorrect key file for table: &#8216;&#8230;&#8217;. Try to repair it<\/span><\/span><\/span><\/li>\n\n\n\n<li><tt class=\"western\"><span style=\"color: #bd4848;\"><span style=\"font-family: Consolas, 'Andale Mono', Courier, 'Courier New', monospace;\"><span style=\"font-size: small;\">126 = Index file is crashed<\/span><\/span><\/span><\/tt><\/li>\n\n\n\n<li><tt class=\"western\"><\/tt><tt class=\"western\"><span style=\"color: #bd4848;\"><span style=\"font-family: Consolas, 'Andale Mono', Courier, 'Courier New', monospace;\"><span style=\"font-size: small;\">127 = Record-file is crashed<\/span><\/span><\/span><\/tt><\/li>\n\n\n\n<li><tt class=\"western\"><\/tt><tt class=\"western\"><span style=\"color: #bd4848;\"><span style=\"font-family: Consolas, 'Andale Mono', Courier, 'Courier New', monospace;\"><span style=\"font-size: small;\">134 = Record was already deleted (or record file crashed)<\/span><\/span><\/span><\/tt><\/li>\n\n\n\n<li><tt class=\"western\"><\/tt><tt class=\"western\"><span style=\"color: #bd4848;\"><span style=\"font-family: Consolas, 'Andale Mono', Courier, 'Courier New', monospace;\"><span style=\"font-size: small;\">144 = Table is crashed and last repair failed<\/span><\/span><\/span><\/tt><\/li>\n\n\n\n<li><tt class=\"western\"><\/tt><tt class=\"western\"><span style=\"color: #bd4848;\"><span style=\"font-family: Consolas, 'Andale Mono', Courier, 'Courier New', monospace;\"><span style=\"font-size: small;\">145 = Table was marked as crashed and should be repaired<\/span><\/span><\/span><\/tt><\/li>\n<\/ul>\n\n\n\n<p>So how do we repair those tables which are corrupted? &nbsp;First, we need to know the name of those tables in order to proceed.<\/p>\n\n\n\n<p>You can run the command <strong>&#8220;mysqlcheck -u root -p &nbsp;&#8211;all-databases&#8221;<\/strong> to find all corrupted databases.<\/p>\n\n\n\n<p>So let&#8217;s start by logging into the server by SSH, and following these steps<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><tt class=\"western\"><span style=\"color: #bd4848;\"><span style=\"font-family: Consolas, 'Andale Mono', Courier, 'Courier New', monospace;\"><span style=\"font-size: small;\">[root@test ~]#<\/span><\/span><\/span><\/tt><strong><span style=\"color: #bd4848;\"><span style=\"font-family: Consolas, 'Andale Mono', Courier, 'Courier New', monospace;\"><span style=\"font-size: small;\">&nbsp;mysql -u root -p<\/span><\/span><\/span><\/strong><tt class=\"western\"><span style=\"color: #bd4848;\"><span style=\"font-family: Consolas, 'Andale Mono', Courier, 'Courier New', monospace;\"><span style=\"font-size: small;\">&nbsp;(type in the password when prompted)<\/span><\/span><\/span><\/tt>&nbsp;<\/li>\n\n\n\n<li><strong><span style=\"color: #bd4848;\"><span style=\"font-family: Consolas, 'Andale Mono', Courier, 'Courier New', monospace;\"><span style=\"font-size: small;\">mysql&gt;&nbsp;USE<\/span><\/span><\/span><\/strong><span style=\"color: #bd4848;\"><span style=\"font-family: Consolas, 'Andale Mono', Courier, 'Courier New', monospace;\"><span style=\"font-size: small;\">&nbsp;&lt;database_name&gt;<\/span><\/span><\/span><strong><span style=\"color: #bd4848;\"><span style=\"font-family: Consolas, 'Andale Mono', Courier, 'Courier New', monospace;\"><span style=\"font-size: small;\">;<\/span><\/span><\/span><\/strong>&nbsp;<\/li>\n\n\n\n<li><strong><span style=\"color: #bd4848;\"><span style=\"font-family: Consolas, 'Andale Mono', Courier, 'Courier New', monospace;\"><span style=\"font-size: small;\">mysql&gt;&nbsp;CHECK TABLE<\/span><\/span><\/span><\/strong><span style=\"color: #bd4848;\"><span style=\"font-family: Consolas, 'Andale Mono', Courier, 'Courier New', monospace;\"><span style=\"font-size: small;\">&nbsp;&lt;table_name&gt;<\/span><\/span><\/span><strong><span style=\"color: #bd4848;\"><span style=\"font-family: Consolas, 'Andale Mono', Courier, 'Courier New', monospace;\"><span style=\"font-size: small;\">;<\/span><\/span><\/span><\/strong><span style=\"color: #bd4848;\"><span style=\"font-family: Consolas, 'Andale Mono', Courier, 'Courier New', monospace;\"><span style=\"font-size: small;\">&nbsp;(You can see that the output as <strong>NOT OK<\/strong>, go to step 3, else the table is fine)<\/span><\/span><\/span>\n<pre class=\"lang-sql prettyprint prettyprinted\"><code><span class=\"pln\">mysql<\/span><span class=\"pun\">&gt;<\/span> <span class=\"kwd\">check<\/span> <span class=\"kwd\">table<\/span><span class=\"pln\"> MySql_table<\/span><strong><span class=\"pun\">;<\/span><\/strong>\n<span class=\"pun\">+<\/span><span class=\"com\">--------------------------------+-------+----------+----------+<\/span>\n<span class=\"pun\">|<\/span> <span class=\"kwd\">Table<\/span>                          <span class=\"pun\">|<\/span><span class=\"pln\"> Op    <\/span><span class=\"pun\">|<\/span><span class=\"pln\"> Msg_type <\/span><span class=\"pun\">|<\/span><span class=\"pln\"> Msg_text <\/span><span class=\"pun\">|<\/span>\n<span class=\"pun\">+<\/span><span class=\"com\">--------------------------------+-------+----------+----------+<\/span>\n<span class=\"pun\">|<\/span><span class=\"pln\"> database<\/span><span class=\"pun\">.MySql_table<\/span> <span class=\"pun\">|<\/span> <span class=\"kwd\">check<\/span> <span class=\"pun\">|<\/span><span class=\"pln\"> status   <\/span><span class=\"pun\">|<\/span><span class=\"pln\"> OK       <\/span><span class=\"pun\">| OK<\/span>\n<span class=\"pun\">+<\/span><span class=\"com\">--------------------------------+-------+----------+----------+<\/span><\/code><\/pre>\n<p>&nbsp;<\/p>\n<\/li>\n\n\n\n<li><strong><span style=\"color: #bd4848;\"><span style=\"font-family: Consolas, 'Andale Mono', Courier, 'Courier New', monospace;\"><span style=\"font-size: small;\">mysql&gt;&nbsp;REPAIR TABLE<\/span><\/span><\/span><\/strong><tt class=\"western\"><span style=\"color: #bd4848;\"><span style=\"font-family: Consolas, 'Andale Mono', Courier, 'Courier New', monospace;\"><span style=\"font-size: small;\">&nbsp;&lt;table_name&gt;<\/span><\/span><\/span><\/tt><strong><span style=\"color: #bd4848;\"><span style=\"font-family: Consolas, 'Andale Mono', Courier, 'Courier New', monospace;\"><span style=\"font-size: small;\">;<\/span><\/span><\/span><\/strong><tt class=\"western\"><span style=\"color: #bd4848;\"><span style=\"font-family: Consolas, 'Andale Mono', Courier, 'Courier New', monospace;\"><span style=\"font-size: small;\">&nbsp;(which will provide an output as below) <\/span><\/span><\/span><\/tt>\n<pre class=\"lang-sql prettyprint prettyprinted\"><code><span class=\"pln\">mysql<\/span><span class=\"pun\">&gt;<\/span> repair <span class=\"kwd\">table<\/span><span class=\"pln\"> MySql_table<\/span><span class=\"pun\">;<\/span>\n<span class=\"pun\">+<\/span><span class=\"com\">--------------------------------+-------+----------+----------+<\/span>\n<span class=\"pun\">|<\/span> <span class=\"kwd\">Table<\/span>                          <span class=\"pun\">|<\/span><span class=\"pln\"> Op    <\/span><span class=\"pun\">|<\/span><span class=\"pln\"> Msg_type <\/span><span class=\"pun\">|<\/span><span class=\"pln\"> Msg_text <\/span><span class=\"pun\">|<\/span>\n<span class=\"pun\">+<\/span><span class=\"com\">--------------------------------+-------+----------+----------+<\/span>\n<span class=\"pun\">|<\/span><span class=\"pln\"> database<\/span><span class=\"pun\">.MySql_table<\/span> <span class=\"pun\">|<\/span> repair <span class=\"pun\">|<\/span><span class=\"pln\"> status   <\/span><span class=\"pun\">|<\/span><span class=\"pln\"> OK       <\/span><span class=\"pun\">| OK<\/span>\n<span class=\"pun\">+<\/span><span class=\"com\">--------------------------------+-------+----------+----------+<\/span><\/code><\/pre>\n<\/li>\n<\/ol>\n\n\n\n<p>So that&#8217;s how you repair a corrupted MySql table. This way of repairing tables can be performed while the MySql service is up and running. You can use the <strong>&#8220;<a href=\"https:\/\/www.interserver.net\/tips\/kb\/use-myisamcheck-mysqlcheck\/\" target=\"_blank\" rel=\"noopener\">myisamchk<\/a>&#8221; <\/strong>utility<strong>&nbsp;<\/strong>to repair corrupted tables provided that the MySql service is turned off.<\/p>\n\n\n\n<p>That&#8217;s all Folks..!!<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;<\/pre>\n\n\n\n<div class=\"wp-block-uagb-call-to-action uagb-block-74a18546 wp-block-button\"><div class=\"uagb-cta__wrap\"><h3 class=\"uagb-cta__title\">Deploy Faster, Optimize Costs \u2013 AWS Hosting Simplified by Veeble!<\/h3><p class=\"uagb-cta__desc\">Maximize ROI with hassle-free AWS hosting. We optimize costs, ensure compliance, and provide round-the-clock support\u2014so you can scale confidently without technical headaches.<\/p><\/div><div class=\"uagb-cta__buttons\"><a href=\"https:\/\/sandbox.veeble.com\/managed-aws-hosting\/\" class=\"uagb-cta__button-link-wrapper wp-block-button__link\" target=\"_blank\" rel=\"noopener noreferrer\">Get Started Now<svg xmlns=\"https:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\"><path d=\"M504.3 273.6l-112.1 104c-6.992 6.484-17.18 8.218-25.94 4.406c-8.758-3.812-14.42-12.45-14.42-21.1L351.9 288H32C14.33 288 .0002 273.7 .0002 255.1S14.33 224 32 224h319.9l0-72c0-9.547 5.66-18.19 14.42-22c8.754-3.809 18.95-2.075 25.94 4.41l112.1 104C514.6 247.9 514.6 264.1 504.3 273.6z\"><\/path><\/svg><\/a><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Why does the database crash!? What can we do if it does? Database corruption can be due to many scenarios, like when a query [&hellip;]<\/p>\n","protected":false},"author":10,"featured_media":7492,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[11],"tags":[],"class_list":["post-361","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mysql"],"uagb_featured_image_src":{"full":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2015\/05\/How-to-recover-Corrupted-Table-MySql.jpg",1366,768,false],"thumbnail":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2015\/05\/How-to-recover-Corrupted-Table-MySql-150x150.jpg",150,150,true],"medium":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2015\/05\/How-to-recover-Corrupted-Table-MySql-300x169.jpg",300,169,true],"medium_large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2015\/05\/How-to-recover-Corrupted-Table-MySql-768x432.jpg",768,432,true],"large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2015\/05\/How-to-recover-Corrupted-Table-MySql-1024x576.jpg",1024,576,true],"1536x1536":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2015\/05\/How-to-recover-Corrupted-Table-MySql.jpg",1366,768,false],"2048x2048":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2015\/05\/How-to-recover-Corrupted-Table-MySql.jpg",1366,768,false]},"uagb_author_info":{"display_name":"Vipin Raj","author_link":"https:\/\/www.veeble.com\/kb\/author\/vipin\/"},"uagb_comment_info":0,"uagb_excerpt":"Why does the database crash!? What can we do if it does? Database corruption can be due to many scenarios, like when a query [&hellip;]","_links":{"self":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/361","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/comments?post=361"}],"version-history":[{"count":14,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/361\/revisions"}],"predecessor-version":[{"id":8303,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/361\/revisions\/8303"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media\/7492"}],"wp:attachment":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media?parent=361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/categories?post=361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/tags?post=361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}