MySQL数据库错误server_errno=2013的解决

MySQL数据库错误server_errno=2013的解决

  一组MySQL复制环境中的Master意外掉电,重启后Master运行正常,但该复制环境中的其它slave端,Error Log中却抛出的如下错误信息:

Version: ‘5.6.17-log‘  socket: ‘‘  port: 3306  MySQL Community Server (GPL)
2014-09-26 18:30:19 5940 [Warning] Slave SQL: If a crash happens this configuration does not guarantee that the relay log info will be consistent, Error_code: 0
2014-09-26 18:30:19 5940 [Note] Slave SQL thread initialized, starting replication in log ‘FIRST‘ at position 0, relay log ‘.\Q12MB1DR67JGLJT-relay-bin.000001‘ position: 4
2014-09-26 18:30:19 5940 [Note] Slave I/O thread: connected to master ‘[email protected]:3306‘,replication started in log ‘FIRST‘ at position 4
2014-09-26 18:30:19 5940 [Warning] Slave I/O: Notifying master by SET @master_binlog_checksum= @@global.binlog_checksum failed with error: Unknown system variable ‘binlog_checksum‘, Error_code: 1193
2014-09-26 18:30:19 5940 [Warning] Slave I/O: Unknown system variable ‘SERVER_UUID‘ on master. A probable cause is that the variable is not supported on the master (version: 5.5.35-log), even though it is on the slave (version: 5.6.17-log), Error_code: 1193
2014-09-26 18:31:14 5940 [Note] Error reading relay log event: slave SQL thread was killed
2014-09-26 18:31:15 5940 [ERROR] Error reading packet from server: Lost connection to MySQL server during query ( server_errno=2013)
2014-09-26 18:31:15 5940 [Note] Slave I/O thread killed while reading event
2014-09-26 18:31:15 5940 [Note] Slave I/O thread exiting, read up to log ‘binLog.000001‘, position 278
2014-09-26 18:31:20 5940 [Note] ‘CHANGE MASTER TO executed‘. Previous state master_host=‘115.29.36.149‘, master_port= 3306, master_log_file=‘binLog.000001‘, master_log_pos= 278, master_bind=‘‘. New state master_host=‘115.29.36.149‘, master_port= 3306, master_log_file=‘‘, master_log_pos= 4, master_bind=‘‘.
2014-09-26 18:35:27 5940 [Note] ‘CHANGE MASTER TO executed‘. Previous state master_host=‘115.29.36.149‘, master_port= 3306, master_log_file=‘‘, master_log_pos= 4, master_bind=‘‘. New state master_host=‘115.29.36.149‘, master_port= 3306, master_log_file=‘‘, master_log_pos= 4, master_bind=‘‘.

110110 15:21:25 [ERROR] Error reading packet from server: Lost connection to MySQL server during query ( server_errno=2013)
110110 15:21:25 [Note] Slave I/O thread: Failed reading log event, reconnecting to retry, log ‘forummysql01-bin.002937‘ position 243387731
110110 15:21:25 [Note] Slave: connected to master ‘[email protected]:3306‘,replication resumed in log ‘forummysql01-bin.002937‘ at position 243387731
110110 15:21:25 [ERROR] Error reading packet from server: Client requested master to start replication from impossible position ( server_errno=1236)
110110 15:21:25 [ERROR] Got fatal error 1236: ‘Client requested master to start replication from impossible position‘ from master when reading data from binary log
110110 15:21:25 [Note] Slave I/O thread exiting, read up to log ‘forummysql01-bin.002937‘, position 243387731

通过mysql命令行连接到slave端,执行show slave status查看复制状态:

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State:
                  Master_Host: 115.29.36.149
                  Master_User: c
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File:
          Read_Master_Log_Pos: 4
               Relay_Log_File: Q12MB1DR67JGLJT-relay-bin.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File:
             Slave_IO_Running: No
            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: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 0
              Relay_Log_Space: 120
              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: 1593
                Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave have
 equal MySQL server ids; these ids must be different for replication to work (or the --replicate-sam
e-server-id option must be used on slave but this does not always make sense; please check the manua
l before using it).
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 1
                  Master_UUID:
             Master_Info_File: F:\db-data\mysql\master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State:
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp: 140926 19:17:52
     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)

Salve的io线程没有运行,看起来是接收日志出现了问题,尝试启动该线程:start slave io_thread;

mysql> start slave io_thread ;
Query OK, 0 rows affected (0.00 sec)

再次执行show slave status查看复制状态:

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State:
                  Master_Host: 115.29.36.149
                  Master_User: c
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File:
          Read_Master_Log_Pos: 4
               Relay_Log_File: Q12MB1DR67JGLJT-relay-bin.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File:
             Slave_IO_Running: No
            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: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 0
              Relay_Log_Space: 120
              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: 1593
                Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave have
 equal MySQL server ids; these ids must be different for replication to work (or the --replicate-sam
e-server-id option must be used on slave but this does not always make sense; please check the manua
l before using it).
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 1
                  Master_UUID:
             Master_Info_File: F:\db-data\mysql\master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State:
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp: 140926 19:25:12
     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)

  看起来 没有反应,其中是有反映,执行启动io线程的命令后,Error Log文件中又抛出了日志文件位置异常的信息。看来还是得到master端,查看一下报错的日志文件指定位置到底执行的什么操作,以及该位置是否存在?

  通过mysqlbinlog命令可以查看二进制日志文件中的内容,在master端执行命令如下:

[[email protected] data]# mysqlbinlog --start-position=243387732 forummysql01-bin.002937
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @[email protected]@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET [email protected]_COMPLETION_TYPE*/;

  还别说,这个位置看起来啥都没有做,稳妥起见,三思将整个forummysql01-bin.002937文件中的内容均提取出来查看一下,再次执行mysqlbinlog命令,这次不再指定position:

[[email protected] data]# mysqlbinlog ./forummysql01-bin.002937 > /home/jss/bin-002937.log

我们只需要查看一下该文件最后几行的信息即可,例如:

[[email protected] data]# tail -50 /home/jss/bin-002937.log
.............................
# at 243297123
#110110 15:02:19 server id 1 end_log_pos 243297459 Query thread_id=1773644066 exec_time=0 error_code=0
SET TIMESTAMP=1294642939/*!*/;
INSERT INTO cdb_sessions (sid, ip1, ip2, ip3, ip4, uid, username, groupid, styleid, invisible, action, lastactivity, lastolupdate, seccode, fid, tid)
VALUES (‘HQFzjy‘, ‘202‘, ‘160‘, ‘180‘, ‘187‘, ‘0‘, ‘‘, ‘7‘, ‘1‘, ‘0‘, ‘3‘, ‘1294642939‘, ‘0‘, ‘232485‘, ‘27‘, ‘4583‘)
/*!*/;
................
................
................

# at 243308840
#110110 15:02:20 server id 1 end_log_pos 243315309 Query thread_id=1773638971 exec_time=0 error_code=0
SET TIMESTAMP=1294642940/*!*/;
update group_topic set TOPIC_TIT.............................
/*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET [email protected]_COMPLETION_TYPE*/;

  可以看到该bin文件中最后的位置点是243315309,与错误日志中“‘forummysql01-bin.002937‘, position 243387731”相差较大,提示的错误点在二进制日志文件中确实不存在,我将其理解为逻辑错误,应该是由于master意外掉电,重新启动时自动flush了binlog,而slave并未获取到这个信息导致,因此解决该问题也比较简单,直接重置同步的master位置应该就可以。这里三思选择将日志文件序号递增(也可以选择将position位置号提前),执行命令如下:

mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)
mysql> CHANGE MASTER TO MASTER_HOST=‘192.168.1.101‘,
-> MASTER_PORT=3306,
-> MASTER_USER=‘repl‘,
-> MASTER_PASSWORD=‘******‘,
-> MASTER_LOG_FILE=‘forummysql01-bin.002938‘,
-> MASTER_LOG_POS=0;
Query OK, 0 rows affected (0.01 sec)

然后再重新启动slave,查看状态:

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.31
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: forummysql01-bin.002938
Read_Master_Log_Pos: 35910271
Relay_Log_File: phpmysql02-relay-bin.000003
Relay_Log_Pos: 21407790
Relay_Master_Log_File: forummysql01-bin.002938
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB: mysql
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: 21407646
Relay_Log_Space: 35910415
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: 2215
1 row in set (0.00 sec)

  Slave相关进程已启动,Error Log文件中也没有再抛出错误信息。等待一段时间,让slave赶上master的进度,其它slave也参照此步骤操作,整个复制环境就恢复了。

来自  : http://blog.itpub.net/7607759/viewspace-683607/

  

时间: 2024-10-05 20:49:32

MySQL数据库错误server_errno=2013的解决的相关文章

关于MySQL数据库错误号码2003的解决方法

一.问题如下 二.解决方法 重启服务 右键我的电脑,选择管理属性,单击进去 选择服务目录,查找MySQL项目,双击启动. 原文地址:https://www.cnblogs.com/guo7533/p/8448216.html

MySQL数据库ab主从复制出错及解决过程

MySQL数据库ab主从复制出错及解决过程 一.mysql主从服务器报错描述:Slave_IO_Running=NO,Slave_SQL_Running=YES,Last_Errno=0 mysql slave stop ; mysql slave start; mysql show slave status ; 如果Slave_IO_Running=YES ...解决过程 :1 如果:Slave_IO_Running=NO,Slave_SQL_Running=YES,Last_Errno=0m

centos安装LAMP环境时访问本地MYSQL数据库错误

近日在安装LAMP环境时访问本地MYSQL数据库错误 错误如下: Warning: mysqli::mysqli(): (HY000/2002): Can't connect to local MySQL server 问题描述: 由于将安装mysql服务器文件位置修改在home目录下,造成本地访问问题. 在网上找了很久终于找到解决问题的方法: 1.先确保在本机上使用命令能登陆,如果也出现提示sock文件位置问题,那么需要修改mysql配置文件(/etc/my.cnf) 增加如下配置: [mys

关于php读mysql数据库时出现乱码的解决方法

关于php读mysql数据库时出现乱码的解决方法 php读mysql时,有以下几个地方涉及到了字符集. 1.建立数据库表时指定数据库表的字符集.例如 create table tablename ( id int not null auto_increment, title varchar(20) not null, primary key ('id') )DEFAULT CHARSET =UTF8; 复制代码 2. mysql的字符集 mysql中有三个重要的变量,character_set_

mysql数据库错误解决方法

ERROR 1046 (3D000): No database selected 错误解释:没有选中数据库 ----原因:没有打开相应的数据库(创建表和对表的操作需要在数据库下进行操作) ----解决:打开数据库:use 数据库名 ERROR 1050 (42S01): Table 'tb_name' already exists 错误解释:表"tb_name"已经存在 ----原因:重复创建相同名字的数据表 ----解决:修改数据表的名字或已存在的表不重复创建 ERROR 1406 

mysql数据库存储中文数据的解决办法

我在学习django中admin模块的时候,登录进入后台操作页面,输入中文数据,但保存之后全是乱码(全是“????????????”),然后就开始了解决问题之路. 1.首先百度搜索,最主流的方法也是一劳永逸的方法是:修改MySQL的配置文件my.ini.我也是按照这个方法做的,只是搜索出来的方法不详细,或者说不适合MySQL的新版本. 2.在MySQL根目录下寻找my.ini配置文件,然而我装的是MySQL-5.6.30,在根目录下只找到了my-default.ini文件.把my-default

Linux下修改MySQL数据库字符编码为UTF-8解决中文乱码

由于MySQL编码原因会导致数据库出现乱码. 解决办法: 修改MySQL数据库字符编码为UTF-8,UTF-8包含全世界所有国家需要用到的字符,是国际编码. 具体操作: 1.进入MySQL控制台 >mysql -uroot -p #输入密码进入 >status; #查看当前MySQL运行状态,如下图所示: 2.修改mysql配置文件 [[email protected] ~]# vi /etc/my.cnf #在[client]段增加下面代码 default-character-set=utf

VC连接mysql数据库错误:libmysql.lib : fatal error LNK1113: invalid machine 解决方法

VC连接MySQL的配置过程在上一篇博文中,不过当你设置好,以为万事大吉的时候,运行却出现这个错误:libmysql.lib : fatal error LNK1113: invalid machine type. 无效的机器类型,真的是很让人捉急. 发生这个错误的原因是,我在win8.1上安装的是64bit的mysql服务器,而我编译32位的VC程序,连接的是64位的libmysql.lib库,所以会产生 “无效的机器类型(invalid machine type)”的错误提示. 对于这个“e

mysql数据库主从不同步的解决方法

故障描述: 进入从数据库 mysql> show slave status\G; 结果如下: ... Slave_IO_Running: Yes Slave_SQL_Running: No Last_Errno: 1062 ... 原因: 程序可能在slave上进行了写操作 可能是slave机器重启后,事物回滚造成的 多数是第二种造成的 解决方法一:忽略错误后继续同步 该方法适用于主从库数据相差不大,或者要求数据可以不完全统一的情况,数据要求不严格的情况 mysql> slave stop;m