Mysql迁移新环境索引损坏

技术支持产品从新部署一套环境。由运维迁移后Mysql发现好多表使用不了
慢sql:mysql

> select n.news_id,n.url,n.source_id,n.tmcreate,n.caption,s.source_name from wly_news as n left join wly_source as s on n.source_id=s.source_id where 1 and s.source_id in (68663,68666,68667,68669,68684,68755) order by n.news_id desc limit 0,10

查看日志:sql

[ERROR] /usr/libexec/mysqld: Incorrect key file for table '/tmp/#sql_2f1c_21.MYI'; try to repair it
好吧,准备修复数据吧。服务器

和运维沟通……扯了半天没解决问题。最终本身解决:运维

尝试键了几个索引,依然不行拔苗助长(具体能够百度,多表联查索引问题)……url

因而删除新增索引,使用表修复命令:日志

数据表大部分使用的是MyISAM。众所周知,MyISAM表在服务器意外宕机或者mysqld进程挂掉之后,MyISAM表会损坏,数据小的话修复还比较快,可是数据若是有10G以上,那就悲剧了。那咱们如何加快repair table快速高效执行呢?下面咱们来看看解决方法。code

首先经过repair table修复:索引

mysql> repair table test;
 +—————+——–+———-+———————————————————+
 | Table         | Op     | Msg_type | Msg_text                                                |
 +—————+——–+———-+———————————————————+
 | test.test | repair | Error    | Incorrect key file for table ‘test’; try to repair it |
 | test.test | repair | error    | Corrupt

若是仍是没用,运行下面命令进程

mysql> repair table test USE_FRM;
 +—————+——–+———-+———————————————————+
 | Table         | Op     | Msg_type | Msg_text                                                |
 +—————+——–+———-+———————————————————+
 | test.test | repair | Error    |Number of rows changed from 0 to 110423 |
 | test.test | repair | status   | OK

按理应该能够了(这一步已经解决问题)。
若是仍是没用,则退出mysql,执行以下修复动做:部署

myisamchk -of /var/lib/mysql/test/test.MYI
 myisamchk -r /var/lib/mysql/test/test.MYI
 myisamchk safe-recover /var/lib/mysql/test/test.MYI

再重启mysql后应该能够正常了。

相关文章
相关标签/搜索