{"id":2258,"date":"2013-07-12T15:24:18","date_gmt":"2013-07-12T07:24:18","guid":{"rendered":"http:\/\/rmohan.com\/?p=2258"},"modified":"2013-07-12T15:24:35","modified_gmt":"2013-07-12T07:24:35","slug":"how-to-repair-a-mysql-table","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=2258","title":{"rendered":"How to Repair a Mysql Table"},"content":{"rendered":"<div>Repairing corrupted mysql tables using\u00a0myisamchk \/ mysqlcheck\u00a0\/ repair<\/div>\n<div><\/div>\n<div><b>1. myisamchk<\/b><\/div>\n<div>\u00a0myisam is the default storage engine for mysql database. There is a chance of myisam tables gets corrupted easily. myisamchk helps to identify and fix corrupted tables in myisam.<\/div>\n<div><\/div>\n<div>when table created in mysql it will create different files under mysql some of them are *.MYD (mydata ) file to store data, *.MYI (myindex) to store the index and *.frm to store table format.<\/div>\n<div><\/div>\n<div>you have to shutdown\u00a0mysqld\u00a0before performing the repair<\/div>\n<div><\/div>\n<div><b>Checking\u00a0<\/b>all corrupted tables using myisamchk<\/div>\n<div># myisamchk -c \/var\/lib\/mysql\/*.MYI &gt;&gt; \/tmp\/log.txt<\/div>\n<div><\/div>\n<div>redirect the output to a file then it will display only corrupted table names on the screen. log.txt contains info about all tables including good ones.<\/div>\n<div><\/div>\n<div><b>Repair\u00a0<\/b>the corrupted table using myisamchk<\/div>\n<div># myisamchk -r \/var\/lib\/mysql\/*.MYI<\/div>\n<div><\/div>\n<div><b>2.mysqlcheck<\/b><\/div>\n<div><\/div>\n<div>It is a client performs table maintenance: It checks, repairs, optimizes, or analyzes tables<b>\u00a0<\/b>etc<b>.\u00a0<\/b>It checks all tables and repair them if necessary<b>.<\/b><\/div>\n<div><\/div>\n<div>both\u00a0mysqlcheck\u00a0and\u00a0myisamchk\u00a0are similar, but works differently. The main difference is that\u00a0mysqlcheck\u00a0must be used when the\u00a0mysqld\u00a0server is running, whereas\u00a0myisamchk\u00a0should be used when it is not. The benefit of usingmysqlcheck\u00a0is that you do not have to stop the server to perform table maintenance.<\/div>\n<div><\/div>\n<div><b>Checking\u00a0<\/b>tables using mysqlcheck<\/div>\n<div><\/div>\n<pre>mysql&gt; <code>mysqlcheck [<i><code>options<\/code><\/i>] <i><code>db_name<\/code><\/i> <i><code>tbl_name<\/code><\/i><\/code><b><code> <\/code><\/b>\r\nmysql&gt; <code>mysqlcheck [<i><code>options<\/code><\/i>] --databases <i><code> db_name<\/code><\/i><\/code><b><code> <\/code><\/b>\r\nmysql&gt; <code>mysqlcheck [<i><code>options<\/code><\/i>] --all-databases<\/code><\/pre>\n<pre><b><code>some options include<\/code><\/b><b><code><\/code><\/b>  --auto-repair,--check -c<\/pre>\n<pre><b>Repair <\/b>tables with mysqlcheck<\/pre>\n<pre># mysqlcheck -uroot -p -r tablename;<\/pre>\n<pre><b>3.REPAIR\u00a0<\/b><\/pre>\n<pre># repair table tablename;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Repairing corrupted mysql tables using myisamchk \/ mysqlcheck \/ repair 1. myisamchk myisam is the default storage engine for mysql database. There is a chance of myisam tables gets corrupted easily. myisamchk helps to identify and fix corrupted tables in myisam. when table created in mysql it will create different files under mysql some of [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2258"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2258"}],"version-history":[{"count":2,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2258\/revisions"}],"predecessor-version":[{"id":2260,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2258\/revisions\/2260"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2258"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2258"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2258"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}