突然收到告警,提示mysql宕機了,該服務器是從庫。於是嘗試登錄服務器看看能否登錄,發現可以登錄,查看mysql進程也存在,嘗試登錄提示
ERROR 1040 (HY000): Too many connections
最大連接數設置的3000,怎么會連接數不夠了呢。於是使用gdb修改一下最大連接數:
gdb -p $(cat pid_mysql.pid) -ex "set max_connections=5000" -batch
修改以后可以登錄了,於是show processlist看看是啥情況:
發現監控程序執行show slave status都被卡住了,最后把最大連接數用完,導致Too many connections。復制卡在了Waiting for commit lock。查閱資料以后發現是觸發了bug。https://bugs.mysql.com/bug.php?id=70307,改bug在5.6.23已經修復。我的版本是 5.6.17
mysql> SELECT a.trx_id, trx_state, trx_started, b.id AS thread_id, b.info, b.user, b.host, b.db, b.command, b.state FROM information_schema.`INNODB_TRX` a, information_schema.`PROCESSLI ST` b WHERE a.trx_mysql_thread_id = b.id ORDER BY a.trx_started; +----------+-----------+---------------------+-----------+------+-------------+------+------+---------+-------------------------+ | trx_id | trx_state | trx_started | thread_id | info | user | host | db | command | state | +----------+-----------+---------------------+-----------+------+-------------+------+------+---------+-------------------------+ | 51455154 | RUNNING | 2017-08-02 02:20:07 | 6404 | NULL | system user | | NULL | Connect | Waiting for commit lock | +----------+-----------+---------------------+-----------+------+-------------+------+------+---------+-------------------------+ 1 row in set (0.03 sec)
可以看到在凌晨2點左右的時候卡住的,突然發現凌晨2點這個時候正是xtrabackup備份數據的時間。xtrabackup備份的時候執行flushs tables with read lock和show slave status會有可能和SQL Thread形成死鎖,導致SQL Thread一直被卡主。原因是SQL Thread的DML操作完成之后,持有rli->data_lock鎖,commit的時候等待MDL_COMMIT,而flush tables with read lock之后執行的show slave status會等待rli->data_lock;修復方法是rli->data_lock鎖周期只在DML操作期間持有。
stop slave沒有用,正常停止沒有用,最后只能kill -9,問題還是比較嚴重的,解決的方法就是升級新版本。