mysql主从复制中的从库突然出现了警报,sql_thread停止了,show slave status\G;查看

mysql> show slave status\G ;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: IPAddr
Master_User: wxapi_slave3309
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000220
Read_Master_Log_Pos: 545197618
Relay_Log_File: mysql3309-relay-bin.000266
Relay_Log_Pos: 539938558
Relay_Master_Log_File: mysql-bin.000220
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 126
Last_Error: Error 'Incorrect key file for table './ota2scan/wx_order_flow.MYI'; try to repair it' on query. Default database: 'ota2scan'. Query: 'insert into wx_order_flow (id, chain_id, room_type_id,
room_count, source_type_id, arr_date,
dept_date, latest_time, result_code,
result_msg, order_code, meb_id,
meb_type, openId, meb_mobile,
contact_name, contact_phone, revPoint,
assure_type, activity_code, remark,
seller_id, treasure_id, payType,
day_length, room_source_type, guests,
total_amount, actual_amount, create_time,
sn, ip, couponId, usePoint,
useCash, scanType, giftInfo
)
values ('0000181785432-1511410392121', '2501', '220',
1, 123, '2017-11-23',
'2017-11-24', '2017-11-23', null,
null, null, xxxxxxxxxxx,
5, 'oDMTPjnkDTILoxKYOuXRf9nCl-NQ', 'xxxxxxxxxxx',
'xxx', 'xxxxxxxxxxx', null,
0, '', '联系人:xxx,联系方式:xxxxxxxxxxx',
272252, null, 0,
1, '7days', nul
Skip_Counter: 0
Exec_Master_Log_Pos: 539938399
Relay_Log_Space: 545197993
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 126
Last_SQL_Error: Error 'Incorrect key file for table './ota2scan/wx_order_flow.MYI'; try to repair it' on query. Default database: 'ota2scan'. Query: 'insert into wx_order_flow (id, chain_id, room_type_id,
room_count, source_type_id, arr_date,
dept_date, latest_time, result_code,
result_msg, order_code, meb_id,
meb_type, openId, meb_mobile,
contact_name, contact_phone, revPoint,
assure_type, activity_code, remark,
seller_id, treasure_id, payType,
day_length, room_source_type, guests,
total_amount, actual_amount, create_time,
sn, ip, couponId, usePoint,
useCash, scanType, giftInfo
)
values ('0000181785432-1511410392121', '', '',
1, 123, '2017-11-23',
'2017-11-24', '2017-11-23', null,
null, null, 181785432,
5, 'oDMTPjnkDTILoxKYOuXRf9nCl-NQ', 'xxxxxxxxxxx',
'xxx', 'xxxxxxxxxxx', null,
0, '', '联系人:xxx,联系方式:xxxxxxxxxxx',
272252, null, 0,
1, '7days', nul
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID:
Master_Info_File: /data/mysql/3309/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp: 171123 12:26:15
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
1 row in set (0.00 sec) ERROR:
No query specified

  发现原来线上还有在使用myisam引擎的业务表,从报错信息来看,是表损坏了,myisam的表损坏,可以先使用myiasmchk进行检测,然后再使用repair table进行修复

  repair的相关参数如下:

[root@ bin]# myisamchk --help
myisamchk Ver 2.7 for Linux at x86_64
By Monty, for your professional use
This software comes with NO WARRANTY: see the PUBLIC for details. Description, check and repair of MyISAM tables.
Used without options all tables on the command will be checked for errors
Usage: myisamchk [OPTIONS] tables[.MYI] Global options:
-H, --HELP Display this help and exit.
-?, --help Display this help and exit.
-t, --tmpdir=path Path for temporary files. Multiple paths can be
specified, separated by colon (:), they will be used
in a round-robin fashion.
-s, --silent Only print errors. One can use two -s to make
myisamchk very silent.
-v, --verbose Print more information. This can be used with
--description and --check. Use many -v for more verbosity.
-V, --version Print version and exit.
-w, --wait Wait if table is locked. Check options (check is the default action for myisamchk):
-c, --check Check table for errors.
-e, --extend-check Check the table VERY throughly. Only use this in
extreme cases as myisamchk should normally be able to
find out if the table is ok even without this switch.
-F, --fast Check only tables that haven't been closed properly.
-C, --check-only-changed
Check only tables that have changed since last check.
-f, --force Restart with '-r' if there are any errors in the table.
States will be updated as with '--update-state'.
-i, --information Print statistics information about table that is checked.
-m, --medium-check Faster than extend-check, but only finds 99.99% of
all errors. Should be good enough for most cases.
-U --update-state Mark tables as crashed if you find any errors.
-T, --read-only Don't mark table as checked. Repair options (When using '-r' or '-o'):
-B, --backup Make a backup of the .MYD file as 'filename-time.BAK'.
--correct-checksum Correct checksum information for table.
-D, --data-file-length=# Max length of data file (when recreating data
file when it's full).
-e, --extend-check Try to recover every possible row from the data file
Normally this will also find a lot of garbage rows;
Don't use this option if you are not totally desperate.
-f, --force Overwrite old temporary files.
-k, --keys-used=# Tell MyISAM to update only some specific keys. # is a
bit mask of which keys to use. This can be used to
get faster inserts.
--max-record-length=#
Skip rows bigger than this if myisamchk can't allocate
memory to hold it.
-r, --recover Can fix almost anything except unique keys that aren't
unique.
-n, --sort-recover Forces recovering with sorting even if the temporary
file would be very big.
-p, --parallel-recover
Uses the same technique as '-r' and '-n', but creates
all the keys in parallel, in different threads.
-o, --safe-recover Uses old recovery method; Slower than '-r' but can
handle a couple of cases where '-r' reports that it
can't fix the data file.
--character-sets-dir=...
Directory where character sets are.
--set-collation=name
Change the collation used by the index.
-q, --quick Faster repair by not modifying the data file.
One can give a second '-q' to force myisamchk to
modify the original datafile in case of duplicate keys.
NOTE: Tables where the data file is currupted can't be
fixed with this option.
-u, --unpack Unpack file packed with myisampack. Other actions:
-a, --analyze Analyze distribution of keys. Will make some joins in
MySQL faster. You can check the calculated distribution
by using '--description --verbose table_name'.
--stats_method=name Specifies how index statistics collection code should
treat NULLs. Possible values of name are "nulls_unequal"
(default for 4.1/5.0), "nulls_equal" (emulate 4.0), and
"nulls_ignored".
-d, --description Prints some information about table.
-A, --set-auto-increment[=value]
Force auto_increment to start at this or higher value
If no value is given, then sets the next auto_increment
value to the highest used value for the auto key + .
-S, --sort-index Sort index blocks. This speeds up 'read-next' in
applications.
-R, --sort-records=#
Sort records according to an index. This makes your
data much more localized and may speed up things
(It may be VERY slow to do a sort the first time!).
-b, --block-search=#
Find a record, a block at given offset belongs to. Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
The following groups are read: myisamchk
The following options may be given as the first argument:
--print-defaults Print the program argument list and exit.
--no-defaults Don't read default options from any option file,
except for login file.
--defaults-file=# Only read default options from the given file #.
--defaults-extra-file=# Read this file after the global files are read.
--defaults-group-suffix=#
Also read groups with concat(group, suffix)
--login-path=# Read this path from the login file. Variables (--variable-name=value)
and boolean options {FALSE|TRUE} Value (after reading options)
--------------------------------- ----------------------------------------
character-sets-dir (No default value)
data-file-length
keys-used
max-record-length
set-auto-increment
set-collation (No default value)
sort-records
tmpdir (No default value)
key-buffer-size
key-cache-block-size
myisam-block-size
read-buffer-size
write-buffer-size
sort-buffer-size
myisam-sort-buffer-size
sort-key-blocks
decode-bits
ft-min-word-len
ft-max-word-len
ft-stopword-file (No default value)
stats-method nulls_unequal

  修复的步骤如下:

  1、使用myisam带上参数-of,进行修复

[root@ bin]# myisamchk -of /data/mysql//ota2scan/wx_order_flow.MYI
- recovering (with keycache) MyISAM-table '/data/mysql/3309/ota2scan/wx_order_flow.MYI'
Data records:

  2、登录mysql,对表进行repair table

mysql> repair table wx_order_flow;
+------------------------+--------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+------------------------+--------+----------+----------+
| ota2scan.wx_order_flow | repair | status | OK |
+------------------------+--------+----------+----------+
1 row in set (9 min 56.46 sec)

  至此,表已经修复完成。

  若是在执行完第一步之后,还是提示“Error 'Incorrect key file for table”的错误,可以在第一步之后再执行以下步骤

[root@ bin]# myisamchk -r /data/mysql//ota2scan/wx_order_flow.MYI
- recovering (with sort) MyISAM-table '/data/mysql/3309/ota2scan/wx_order_flow.MYI'
Data records:
- Fixing index [root@ bin]# myisamchk /data/mysql//ota2scan/wx_order_flow.MYI

  再执行一次repair table,此时,应该就能修复myisam引擎表,不会再出现“Error 'Incorrect key file for table”的错误

  重新启动sql_thread进程

mysql> start slave sql_thread ;
Query OK, 0 rows affected (0.01 sec)

  检查复制

mysql> show slave status\G ;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: IPAddr
Master_User: wxapi_slave3309
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000220
Read_Master_Log_Pos: 567443411
Relay_Log_File: mysql3309-relay-bin.000266
Relay_Log_Pos: 567443570
Relay_Master_Log_File: mysql-bin.000220
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 567443411
Relay_Log_Space: 567443786
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID:
Master_Info_File: /data/mysql/3309/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
1 row in set (0.00 sec)

  已经恢复正常。

  以上,如有错谬,请不吝指正。

MyISAM引擎表出现“Error 'Incorrect key file for table”的更多相关文章

  1. 数据表损坏:Incorrect key file for table

    最近做项目过程中,调用数据库内容,老是出现一些类似于数据表损坏的提示信息(Incorrect key file for table edison_category),查询不到数据,很是恼火,后来冷静下 ...

  2. mysql出现“Incorrect key file for table”解决办法

    本文来自: https://www.cnblogs.com/zjoch/archive/2013/08/19/3267131.html 今天mysql突然出现以下错误: mysql> selec ...

  3. MySQL表损坏修复【Incorrect key file for table】

    今天机房mysql服务器异常关机,重新启动后报错如下: -- :: [ERROR] /usr/local/mysql/bin/mysqld: Incorrect key file for table ...

  4. mysql中大数据表alter增加字段报错:"1034 Incorrect key file for table 'table_name'; try to repair it"

    mysql中大数据表alter增加字段报错:"1034 Incorrect key file for table 'table_name'; try to repair it" 现 ...

  5. Incorrect key file for table错误解决方法

    问题现象: alter table portal_app_xxxx_xxx add devno varchar(64) NOT NULL DEFAULT '' COMMENT '设备机编',add s ...

  6. mysqld: Incorrect key file for table

    错误 140624 0:53:42 [ERROR] /usr/libexec/mysqld: Incorrect key file for table './xx/xxx.MYI'; try to r ...

  7. java.sql.SQLException: Incorrect key file for table 'C:\Windows\TEMP\#sql578_6e2_68d.MYI'; try to repair it

    java.sql.SQLException: Incorrect key file for table 'C:\Windows\TEMP\#sql578_6e2_68d.MYI'; try to re ...

  8. mysql错误(Incorrect key file for table)

    Incorrect key file for table 'C:\Windows\TEMP\#sql578_6e2_68d.MYI'; try to repair it mysql错误:mysql需要 ...

  9. MySQL 2003 [ERROR] /usr/sbin/mysqld: Incorrect key file for table './keyword_search/keyword.MYI'; try to repair it

    今天对一个有四百多万数据的表增加一个功能时,当做数据插入时,显示没有插入,到Linux的log下面查看了发现下面这条错误信息 在stacOver上面找到这句: 存储引擎(MyISAM)支持修复表.你应 ...

随机推荐

  1. BZOJ3065 带插入区间K小值 || 洛谷P4278

    这是一道让我崩溃的题...... 然鹅洛谷上时限被改然后只有20分......好像所有人都被卡了(雾) 由于替罪羊树不是依靠旋转操作而是依靠暴力重构的方式维护树的平衡,所以我们可以考虑使用替罪羊树套区 ...

  2. HihoCoder - 1172 SG函数应用

    原文讲解很nice,我尝试换种观点 设背面朝上为F,否则T, 那么局面FFFFFF肯定为0 局面FTFFFF可以转为上面局面0,设为1 局面FFTFFF可以转到0,1,设为2 子游戏SG(x)=x 对 ...

  3. an concreate example

    Step 1: Creating Parts 1. Split the geometry 2. Create the INLET part. 3. Create the OUTLET part. 4. ...

  4. PIE SDK栅格数据的金字塔创建

    1. 功能简介 金字塔可用于改善性能,可以加快栅格数据的显示速度.随着放大操作的进行,各个更精细的分辨率等级将逐渐得到绘制;但性能将保持不变:目前PIE SDK支持栅格数据的金字塔创建,下面对栅格数据 ...

  5. 设计模式学习总结(七)适配器模式(Adapter)

    适配器模式主要是通过适配器来实现接口的统一,如要实现国内手机在国外充电,则需要在不同的国家采用不同的适配器来进行兼容! 一.示例展示: 以下例子主要通过给笔记本电脑添加类似手机打电话和发短信的功能来详 ...

  6. 抱歉最近朋友结婚去浪了几天~未来几天会正常更新.今天带来XML文件解析

    三种解析方法 DOM,SAX,XMLPullParse;你以为我要讲三种嘛 错 ,我只讲一种 ,其他两种我只是说下优缺点, 一.DOM解析器 优点: DOM解析器在解析XML文档时,会把文档中的所有元 ...

  7. 案例45-crm练习改写客户列表使用struts2&OGNL

    1 修改CustomerAction代码 2 修改jsp/customer/list.jsp代码 <%@ page language="java" contentType=& ...

  8. TOJ 2749 Absent Substrings

    描述 Given a string of symbols, it’s natural to look it over and see what substrings are present. In t ...

  9. unity5.5 5.6 使用c#6.0或7.0

    http://blog.csdn.net/davied9/article/details/77281393

  10. 如何让JS变量和字符串拼接后,是变量而不是字符串

    今天有个非常有趣的事,因为我需要用JS去实现多语言,就是我在JS文件里定义了不同的变量,尝试用变量拼接字符串组成之前定义好的变量名称,结果拼接之后,显示的却是字符串,而不是变量,所以无法解析 zh_t ...