技術支持產品從新部署一套環境。由運維遷移後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後應該能夠正常了。