一、详细报错信息:
1、执行show slave status\G 卡住 && stop slave也卡住
2、show processlist 发现 Waiting for commit lock NULL 锁
3、错误日志报错主备同步用户认证失败
二、报错原因(分析过程):
1、排查备库日志发现报错用户认证失败
2、在备考上通过mysql -u mysqlbuckup -pxxx -hxxx -P3306 远程连接主库能连接上(排除用户名密码问题)
3、登陆数据库执行show slave status\G 卡住 && stop slave也卡住
4、执行show processlist; 发现system用户等待锁提交。(系统用户等待锁这个现象比较明显)
5、执行查看innodb_trx事务表发现仅有一条事务,并且是事务id是2
三、结论
查看官方网站发现在5.6.23版本之前有这样一个bug。
Bug#19843808
MySQL :: MySQL Community Server 5.6.23 已发布
* Replication: If a client thread on a slave executed FLUSH
TABLES WITH READ LOCK while the master executed a DML,
executing SHOW SLAVE STATUS in the same client became
blocked, causing a deadlock. The fix ensures that the
read lock is only held during the period that the relay
log is being updated and the deadlock is avoided. (Bug
#19843808)
大概意思是 :
备库(备份的时候或者其他逻辑)会执行 FLUSH TABLES WITH READ LOCK 同时sql线程执行DML语句,如果这个时候在执行show slave status 会导致死锁。
四、解决方法:
可在线操作
1、临时解决方案
1)、数据库kill掉阻塞的事务(此问题的事务ID为2,其他环境可能不一样,注意修改)
kill 2
2)、执行show slave status\G(发现有报错)
3)、stop slave; && start slave && show slave status(发现主备状态恢复)
4)、检查发现没有大量等待 show slave status\G命令
二、永久解决方案升级数据库版本到5.6.23及以上版本。