mysql数据库错误1317_Mysql error 1317导致从库复制断开

环境:Percona Server for MySQL 5.5.18

1. 报错日志:

171212 19:59:58 [ERROR] Slave SQL: Query partially completed on the master (error on master: 1317) and was aborted. There is a chance that your master is inconsistent at this point. If you are sure that your master is ok, run this query manually on the slave and then restart the slave with SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; START SLAVE; . Query: 'SAVEPOINT `ZZG`', Error_code: 1317

171212 19:59:58 [ERROR] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE START". We stopped at log 'mysql-bin.000052' position 6786

2. 重现

Terminal A

mysql> begin;

Query OK, 0 rows affected (0.00 sec)

mysql> insert into y select * from x limit 1;

Query OK, 1 row affected (0.00 sec)

Records: 1 Duplicates: 0 Warnings: 0

mysql> savepoint ZZG;

Query OK, 0 rows affected (0.00 sec)

mysql> commit;

Query OK, 0 rows affected (0.00 sec)

Terminal B

在 Terminal A 执行到insert 的时候,执行 kill query,去模拟终止 Terminal A 的insert,此时,Terminal A 继续执行以上操作,直到commit 结束。

解析 Terminal A 的binlog

mysqlbinlog mysql-bin.000052 --base64-output=decode-rows -vv |less

得到以下结果

#171212 20:01:22 server id 1 end_log_pos 7929 Write_rows: table id 62 flags: STMT_END_F

### INSERT INTO test.y

### SET

### @1='def' /* VARSTRING(1536) meta=1536 nullable=0 is_null=0 */

### @2='information_schema' /* VARSTRING(192) meta=192 nullable=0 is_null=0 */

### @3='CHARACTER_SETS' /* VARSTRING(192) meta=192 nullable=0 is_null=0 */

### @4='SYSTEM VIEW' /* VARSTRING(192) meta=192 nullable=0 is_null=0 */

### @5='MEMORY' /* VARSTRING(192) meta=192 nullable=1 is_null=0 */

### @6=10 /* LONGINT meta=0 nullable=1 is_null=0 */

### @7='Fixed' /* VARSTRING(30) meta=30 nullable=1 is_null=0 */

### @8=NULL /* VARSTRING(30) meta=0 nullable=1 is_null=1 */

### @9=384 /* LONGINT meta=0 nullable=1 is_null=0 */

### @10=0 /* LONGINT meta=0 nullable=1 is_null=0 */

### @11=8388480 /* LONGINT meta=0 nullable=1 is_null=0 */

### @12=0 /* LONGINT meta=0 nullable=1 is_null=0 */

### @13=0 /* LONGINT meta=0 nullable=1 is_null=0 */

### @14=NULL /* LONGINT meta=0 nullable=1 is_null=1 */

### @15=2017-12-12 18:54:45 /* DATETIME meta=0 nullable=1 is_null=0 */

### @16=NULL /* DATETIME meta=0 nullable=1 is_null=1 */

### @17=NULL /* DATETIME meta=0 nullable=1 is_null=1 */

### @18='utf8_general_ci' /* VARSTRING(96) meta=96 nullable=1 is_null=0 */

### @19=NULL /* VARSTRING(96) meta=0 nullable=1 is_null=1 */

### @20='max_rows=21845' /* VARSTRING(765) meta=765 nullable=1 is_null=0 */

### @21='' /* VARSTRING(6144) meta=6144 nullable=0 is_null=0 */

# at 7929

#171212 20:01:38 server id 1 end_log_pos 8007 Query thread_id=3575 exec_time=0 error_code=1317

SET TIMESTAMP=1513080098/*!*/;

SAVEPOINT `ZZG`

/*!*/;

# at 8007

#171212 20:01:45 server id 1 end_log_pos 8034 Xid = 10115

COMMIT/*!*/;

DELIMITER ;

# End of log file

此 error_code=1317 在mysql Master的日志中是不体现的,但是直接导致了从库的复制断开,报错如下

171212 19:59:58 [ERROR] Slave SQL: Query partially completed on the master (error on master: 1317) and was aborted. There is a chance that your master is inconsistent at this point. If you are sure that your master is ok, run this query manually on the slave and then restart the slave with SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; START SLAVE; . Query: 'SAVEPOINT `ZZG`', Error_code: 1317

171212 19:59:58 [ERROR] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE START". We stopped at log 'mysql-bin.000052' position 6786

此时主库是不影响的,主库的insert 正常提交,从库却没有接收到这个insert,如果此时,在从库上执行报错中提示的 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; START SLAVE; 此时将会跳过此事务,继续复制主库。但是主库一旦有对此条或者多条数据的修改,从库的复制将会再次断开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
OTL(Ov{er} The Last Version 4)是一个开源的库,用于在C++中连接和操作数据库。我将使用OTLv4来连接MySQL数据库。 首先,我们需要准备好OTLv4库和MySQL的驱动程序。我们可以从OTL官方网站下载OTLv4库,并且从MySQL官方网站下载MySQL的驱动程序。确保将这些文件保存在适当的目录中,并设置好编译器的相关设置。 接下来,我们需要包含OTL头文件并初始化OTL库。在代码中添加以下代码: #include <otlv4.h> int main() { // 初始化OTL库 otl_connect::otl_initialize(); // 连接MySQL数据库 otl_connect db; try { // 使用MySQL驱动程序连接数据库 db.rlogon("mysql_user_name/mysql_password@mysql_data_source"); // 这里的mysql_user_name是你的MySQL用户名, // mysql_password是你的MySQL密码, // mysql_data_source是你的MySQL数据源地址。 // 执行查询或操作 // 断开数据库连接 db.disconnect(); } catch (otl_exception& e) { // 处理异常 std::cerr << "OTL Error: " << e.msg << std::endl; } // 清理OTL库 otl_connect::otl_terminate(); return 0; } 以上代码演示了如何使用OTLv4连接MySQL数据库。其中,otl_connect类用于表示数据库连接,otl_exception类用于处理异常。在try块中,我们使用驱动程序的rlogon函数连接数据库,并可以在此处执行查询或操作。最后,在catch块中,我们可以处理发生的异常。在代码的结尾处,我们清理OTL库以释放资源。 通过以上步骤,我们就可以使用OTLv4库在C++中连接MySQL数据库

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值