mysql中使用innodb引擎即可, 详见文档:
If you use FOR UPDATE on a storage engine that uses page or row locks, rows examined by the query are write-locked until the end of the current transaction. Using LOCK IN SHARE MODE sets a shared lock that prevents other transactions from updating or deleting the examined rows
If you use FOR UPDATE on a storage engine that uses page or row locks, rows examined by the query are write-locked until the end of the current transaction. Using LOCK IN SHARE MODE sets a shared lock that prevents other transactions from updating or deleting the examined rows
+------+
| a |
+------+
| 10 |
| 20 |
| 30 |
| 10 |
| 10 |
+------+
5 rows in set (0.00 sec)版本是Server version: 5.6.14 MySQL Community Server (GPL)。 innodb engine.
毕竟一个开源,一个收费
select **** for update, 要结合transaction来使用的。
假定使用的是InnoDB引擎,默认是读已提交隔离级,
会话1:
mysql> begin;
Query OK, 0 rows affected (0.00 sec)mysql> select * from t for update;
+----+------+
| id | col2 |
+----+------+
| 1 | wa |
| 2 | ch |
+----+------+
2 rows in set (0.00 sec)mysql>
会话2:
mysql> begin;
Query OK, 0 rows affected (0.00 sec)mysql> update t set col2='ww' where id=1;update操作会hang在那里,与需求相符。直到出现:ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
这时如果会话1,执行commit操作, 会话2的update操作立即完成。
例如我用navicat,我改一条数据。
1)
select * from table where id=222 这个可以直接在显示的行中修改数据。2)
select t.realname,t.address from table t where t.id =222
这个是修改不了的,如果是oracle +for update 是可以修改数据的。
例如我用navicat,我改一条数据。
1)
select * from table where id=222 这个可以直接在显示的行中修改数据。2)
select t.realname,t.address from table t where t.id =222
这个是修改不了的,如果是oracle +for update 是可以修改数据的。
请看我在7楼的回帖,前边要加begin的。
否则for update会失去作用。这是与oracle的区别。
例如我用navicat,我改一条数据。
1)
select * from table where id=222 这个可以直接在显示的行中修改数据。2)
select t.realname,t.address from table t where t.id =222
这个是修改不了的,如果是oracle +for update 是可以修改数据的。
请看我在7楼的回帖,前边要加begin的。
否则for update会失去作用。这是与oracle的区别。select * 不用加for update也能修改。select t.realname,t.address from table t where t.id =222这种是不行的。
我经常用的EMS for mysql,select的数据也可以修改。