HI,
If you face such issue while repairing MySQL database, follow these steps to fix this.
First check the tables status: mysql> CHECK TABLE wp_posts;
+-----------------------+-------+----------+---------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+-----------------------+-------+----------+---------------------------------------------------+
| databasei_wp.sw_posts | check | warning | Table is marked as crashed and last repair failed |
| database_wp.sw_posts | check | error | Found 1768 keys of 16031 |
| database_wp.sw_posts | check | error | Corrupt |
+-----------------------+-------+----------+---------------------------------------------------+
3 rows in set (0.00 sec)
mysql> REPAIR TABLE sw_posts;
+-----------------------+--------+----------+----------------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+-----------------------+--------+----------+----------------------------------------------------------+
| database_wp.sw_posts | repair | error | Can't create new tempfile: './database_wp/sp_posts.TMD' |
| database_wp.sw_posts | repair | status | Operation failed |
+-----------------------+--------+----------+----------------------------------------------------------+
2 rows in set (0.00 sec)
Identify all corrupted tables using myisamchk:------------------------------------
myisamchk /var/lib/mysql/database_wp872/*.MYI >> /tmp/myisamchk_log.txt
myisamchk: warning: 1 client is using or hasn't closed the table properly
MyISAM-table '/var/lib/mysql/databse_wp/sw_postmeta.MYI' is usable but should be fixed
myisamchk: warning: Table is marked as crashed and last repair failed
myisamchk: error: Found 1768 keys of 16031
myisamchk: error: Keypointers and record positions doesn't match
MyISAM-table '/var/lib/mysql/database_wp/sw_posts.MYI' is corrupted
Fix it using switch "-r" or "-o"
------------------------------------
Repair the corrupted table using myisamchk:[root@test]# myisamchk --safe-recover -f /var/lib/mysql/database_wp/sw_posts.MYI
- recovering (with keycache) MyISAM-table '/var/lib/mysql/database_wp/sw_posts.MYI'
Data records: 16031
[root@test]# myisamchk --silent --force --fast --update-state /var/lib/mysql/database_wp/*.MYI
myisamchk: MyISAM file /var/lib/mysql/sesawi_wp872/sw_postmeta.MYI
myisamchk: warning: 1 client is using or hasn't closed the table properly
Finally, check the table's status: [root@test]# myisamchk -dvv /var/lib/mysql/sesawi_wp872/sw_posts.MYI
MyISAM file: /var/lib/mysql/sesawi_wp872/sw_posts.MYI
Record format: Packed
Character set: utf8mb4_unicode_ci (224)
File-version: 1
Creation time: 2016-05-24 16:53:53
Recover time: 2016-05-27 0:47:46
Status: checked
----------------------------------