mysql手册“6.7.3 LOCK TABLES and UNLOCK TABLES Syntax”章节:......All tables that are locked by the current thread are implicitly unlocked when the thread issues another LOCK TABLES, or when the connection to the server is closed......When you use LOCK TABLES, you must lock all tables that you are going to use and you must use the same alias that you are going to use in your queries! If you are using a table multiple times in a query (with aliases), you must get a lock for each alias! ......LOCK TABLES works as follows:
1. Sort all tables to be locked in a internally defined order (from the user standpoint the order is undefined). ......
按以上几点,再经过我自己的测试,我的理解是:
1. 当使用LOCK TABLES时,必须锁定将使用的所有表(包括相同表的所有别名),但不是使用一个一个锁定(在同一个线程里,始终仅仅存在一个有效的锁定),而是LOCK TABLES tbl_name1 READ/WRITE, tbl_name2 READ/WRITE, ....
2. 阅读上述最后一条,再经过测试,最后的现象是:使用一个LOCK TABLES tbl_name后,在同一个线程钟,mysql将首先使用内部定义的某种顺序对所有表进行排序,然后锁定tbl_name之前的所有表(我们不知道它是如何排序的),结果就是对之前的所有表进行操作会显示该表没有被锁定,而对之后的所有表进行操作没有问题!
3. 在2环境下,在打开的另一个mysql连接(即另一个线程)中,对tbl_name的操作显示了我们原先所理解的锁定功能现象!对其它所有表格都可以正常操作
一己之见,请各位高人点评! :-)
1. Sort all tables to be locked in a internally defined order (from the user standpoint the order is undefined). ......
按以上几点,再经过我自己的测试,我的理解是:
1. 当使用LOCK TABLES时,必须锁定将使用的所有表(包括相同表的所有别名),但不是使用一个一个锁定(在同一个线程里,始终仅仅存在一个有效的锁定),而是LOCK TABLES tbl_name1 READ/WRITE, tbl_name2 READ/WRITE, ....
2. 阅读上述最后一条,再经过测试,最后的现象是:使用一个LOCK TABLES tbl_name后,在同一个线程钟,mysql将首先使用内部定义的某种顺序对所有表进行排序,然后锁定tbl_name之前的所有表(我们不知道它是如何排序的),结果就是对之前的所有表进行操作会显示该表没有被锁定,而对之后的所有表进行操作没有问题!
3. 在2环境下,在打开的另一个mysql连接(即另一个线程)中,对tbl_name的操作显示了我们原先所理解的锁定功能现象!对其它所有表格都可以正常操作
一己之见,请各位高人点评! :-)
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货