1.查询是否有锁表/库
show open tables where in_use > 0; -- 有多少线程正在使用某张表
show open tables where name_locked > 0; -- 是否有被锁
show open tables from 库名; -- 针对每一个库。
show open tables; -- 针对所有的库。
2.查进程
show processlist;
找到有锁的进程 ID,杀掉:
kill 6;
kill 7;
3.查看正在锁的事务(被锁的)
select * from information_schema.innodb_trx;
-- 查看 trx_mysql_thread_id,根据这个 ID 处理锁。kill 13;
select * from information_schema.innodb_locks;
4.查看等待锁的事务(可以找到源头,锁人的)
select * from information_schema.innodb_lock_waits;
-- 10018
select * from information_schema.innodb_trx where trx_id=10018;
-- kill 11; trx_mysql_thread_id ,杀源头,会回滚事务,一定要注意了。