MySQL 主從同步失敗,數據表修復


問題描述:mysql

接到報警稱一臺 MySQL 從庫同步失敗。登陸服務器查看錯誤日誌信息以下:sql

Last_Error: Error 'Incorrect key file for table './bfcc/std_user_history.MYI'; 

            try to repair it' on query. Default database: 'bfcc'. 
            
            Query: 'INSERT INTO std_user_history SET vid='685689',vtype='1',utime=1477183694,uid='135601920104863213',num=1,point=0,source='qiyi',tid='1630514',category='9',platform=3'

# 這臺服務器只負責同步數據,不對外提供服務。提示建議嘗試修復該表。shell

解決方法:服務器

shell > mysql -uroot -p

mysql> use bfcc;
mysql> check table std_user_history;
+-----------------------------+-------+----------+-----------------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+-----------------------------+-------+----------+-----------------------------------------------------------+
| bfcc.std_user_history | check | warning | Table is marked as crashed |
| bfcc.std_user_history | check | warning | 21 clients are using or haven't closed the table properly |
| bfcc.std_user_history | check | warning | Size of datafile is: 243026508 Should be: 243026460 |
| bfcc.std_user_history | check | error | Found 5064119 keys of 5064118 |
| bfcc.std_user_history | check | error | Corrupt |
+-----------------------------+-------+----------+-----------------------------------------------------------+
5 rows in set (0.65 sec)

# 看到該表被打上了一些標記,須要修復。

mysql> repair table std_album;

+-----------------------------+--------+----------+------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+-----------------------------+--------+----------+------------------------------------------------+
| bfcc.std_user_history | repair | warning | Number of rows changed from 5064118 to 5064119 |
| bfcc.std_user_history | repair | status | OK |
+-----------------------------+--------+----------+------------------------------------------------+
2 rows in set (58.03 sec)

# 提示修復成功。

mysql > stop slave;

mysql > start slave;

mysql > show slave status\G

# 發現,主從同步恢復正常,只是延遲很大,須要慢慢同步,等待便可。
# 至於產生緣由,有多是頻繁操做該表、服務器異常關機等緣由形成的。
# 以前有一張主庫的表,也出現過這樣的狀況,我以爲應該是操做頻繁致使的。
# 此次的這張表,我感受是服務器問題。這臺服務器不知爲什麼 IO 等待時常 10% 左右,上面跑了一個安卓虛擬機,一個從庫。
# 這臺服務器我已經不對外提供服務了。iotop 顯示佔用 IO 資源的進程倒是 jdb2 這個東西,也查過一些資料,但目前還沒搞定。ui

相關文章
相關標籤/搜索