CREATE TABLE t1
(
id
int(11) NOT NULL,
val
varchar(10) DEFAULT NULL,
PRIMARY KEY (id
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT into t1(id,val) VALUES (12,'888');
select * from t1;
-- 加读表
lock table t1
READ;
-- 然后使用update语句操作 :
update t1
set val= '121' where id=12;
-- 解锁
unlock tables;
-- 加写锁
LOCK TABLE t1
WRITE;
-- 另外开一个线程,尝试运行更新
update t1
set val= '1333' where id=12;
unlock tables;
-- 事务测试
start transaction;
update t1
set val= '1261' where id=12;
-- 另外开一个线程,运行事务
start transaction;
update t1
set val= '176' where id=12;
-- 提交事务
COMMIT;
1、查询进程
show full processlist 查询到相对应的进程===然后 kill id
2、查询是否锁表(查看正在被锁定的的表)
show OPEN TABLES where In_use > 0;
show status like '%lock%'
补充:
查看被锁的表
select * from INFORMATION_SCHEMA.INNODB_TRX;
查看正在锁的事务
SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCKS;
查看等待锁的事务
SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCK_WAITS;