ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
查看数据库的隔离级别:
select @@autocommit;
查看先当前库的线程情况:
show full processlist;
接着查看是否存在命令导致阻塞
+---------+------------+---------------------+----------+---------+------+-------+-----------------------+
| Id | User | Host | db | Command | Time | State | Info |
+---------+------------+---------------------+----------+---------+------+-------+-----------------------+
| 40 | zft_db_all | 10.12.196.158:57793 | NULL | Sleep | 13 | | NULL |
| 71 | zft_db_all | 10.12.196.158:57801 | NULL | Sleep | 18 | | NULL |
| 1371786 | zft_db_all | 10.12.199.249:51419 | c2c_zwdb | Query | 0 | NULL | show full processlist |
+---------+------------+---------------------+----------+---------+------+-------+-----------------------+
如果状态存在sleep的话查看现在的
没有看到正在执行的慢SQL记录线程,再去查看innodb的事务表INNODB_TRX,看下里面是否有正在锁定的事务线程,看看ID是否在show full processlist里面的sleep线程中,如果是,就证明这个sleep的线程事务一直没有commit或者rollback而是卡住了,我们需要手动kill掉。
3,看到有这条9930577的sql,kill掉,执行kill 9930577;
mysql> kill 9930577;
Query OK, 0 rows affected (0.00 sec)
mysql>
然后再去查询INNODB_TRX表,就没有阻塞的事务sleep线程存在了,如下所示:
mysql> SELECT * FROM INNODB_TRX\G;
Empty set (0.00 sec)
ERROR:
No query specified
mysql>
再去执行update语句,就能正常执行了,如下所示:
mysql> update order_info set province_id=15 ,city_id= 1667 where order_from=10 and order_out_sn='1407261241xxxx';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql>