mysql 5.5 lock tables與隱式事務提交commit

wisdomone1發表於2018-01-03
結論:lock tables可以隱式提交其它會話的未提交事務

測試明細:
----session 1
mysql> start transaction;
Query OK, 0 rows affected (0.00 sec)


mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)


mysql> use test;
Database changed


mysql> create table t_commit(a int);
Query OK, 0 rows affected (0.04 sec)


---session 2
mysql> select count(*) from test.t_commit;
+----------+
| count(*) |
+----------+
|        0 |
+----------+
1 row in set (0.01 sec)




---session 1
mysql> insert into t_commit values(1);
Query OK, 1 row affected (0.01 sec)




---session 2
mysql> lock tables test.t_commit read local;
Query OK, 0 rows affected (0.00 sec)


mysql> select count(*) from test.t_commit;
+----------+
| count(*) |
+----------+
|        1 |
+----------+
1 row in set (0.00 sec)

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-2149664/,如需轉載,請註明出處,否則將追究法律責任。

相關文章