本篇文章主要介绍了"事务隔离级别 mysql隔离级别",主要涉及到事务隔离级别方面的内容,对于MySql感兴趣的同学可以参考一下:
原文链接
MySQL InnoDB事务的隔离级别有四级,默认是“可重复读”(REPEATABLE READ)。未提交读(READ UNCOMMITTED)。另...
t Session A Session B
|
| START TRANSACTION; START TRANSACTION;
|
| select * from actor;
+----------+------------+-----------+---------------------+| actor_id | first_name | last_name | last_update |
+----------+------------+-----------+---------------------+
| 1 | PENELOPE | GUINESS | 2006-02-15 04:34:33 |
| 3 | t3 | t3 | 2016-06-16 15:18:33 |
| 4 | t0 | t0 | 2016-06-16 15:18:36 |
| 5 | t5 | t5 | 2016-06-16 16:03:51 |
+----------+------------+-----------+---------------------+
| insert into actor
| values (6,'t6','t6',now());
| COMMIT;
|
| select * from actor;
+----------+------------+-----------+---------------------+| actor_id | first_name | last_name | last_update |
+----------+------------+-----------+---------------------+
| 1 | PENELOPE | GUINESS | 2006-02-15 04:34:33 |
| 3 | t3 | t3 | 2016-06-16 15:18:33 |
| 4 | t0 | t0 | 2016-06-16 15:18:36 |
| 5 | t5 | t5 | 2016-06-16 16:03:51 |
+----------+------------+-----------+---------------------+
|
| select * from actor lock in share mode;
+----------+------------+-----------+---------------------+| actor_id | first_name | last_name | last_update |
+----------+------------+-----------+---------------------+
| 1 | PENELOPE | GUINESS | 2006-02-15 04:34:33 |
| 3 | t3 | t3 | 2016-06-16 15:18:33 |
| 4 | t0 | t0 | 2016-06-16 15:18:36 |
| 5 | t5 | t5 | 2016-06-16 16:03:51 |
| 6 | t6 | t6 | 2016-06-16 16:11:53 |
+----------+------------+-----------+---------------------+
|
| select * from actor for update;
+----------+------------+-----------+---------------------+| actor_id | first_name | last_name | last_update |
+----------+------------+-----------+---------------------+
| 1 | PENELOPE | GUINESS | 2006-02-15 04:34:33 |
| 3 | t3 | t3 | 2016-06-16 15:18:33 |
| 4 | t0 | t0 | 2016-06-16 15:18:36 |
| 5 | t5 | t5 | 2016-06-16 16:03:51 |
| 6 | t6 | t6 | 2016-06-16 16:11:53 |
+----------+------------+-----------+---------------------+
|
| select * from actor;
+----------+------------+-----------+---------------------+| actor_id | first_name | last_name | last_update |
+----------+------------+-----------+---------------------+
| 1 | PENELOPE | GUINESS | 2006-02-15 04:34:33 |
| 3 | t3 | t3 | 2016-06-16 15:18:33 |
| 4 | t0 | t0 | 2016-06-16 15:18:36 |
| 5 | t5 | t5 | 2016-06-16 16:03:51 |
+----------+------------+-----------+---------------------+
v
如果使用普通的读,会得到一致性的结果,如果使用了加锁的读,就会读到“最新的”“提交”读的结果。
本身,可重复读和提交读是矛盾的。在同一个事务里,如果保证了可重复读,就会看不到其他事务的提交,违背了提交读;如果保证了提交读,就会导致前后两次读到的结果不一致,违背了可重复读。
可以这么讲,InnoDB提供了这样的机制,在默认的可重复读的隔离级别里,可以使用加锁读去查询最新的数据。
http://dev.mysql.com/doc/refman/5.0/en/innodb-consistent-read.html
If you want to see the “freshest” state of the database, you should use either the READ COMMITTED isolation level or a locking read:
SELECT * FROM t_bitfly LOCK IN SHARE MODE;
结论:MySQL InnoDB的可重复读并不保证避免幻读,需要应用使用加锁读来保证。而这个加锁度使用到的机制就是next-key locks。
').addClass('pre-numbering').hide();
$(this).addClass('has-numbering').parent().append($numbering);
for (i = 1; i <= lines; i++) {
$numbering.append($('
').text(i));
};
$numbering.fadeIn(1700);
});
});
以上就介绍了事务隔离级别 mysql隔离级别,包括了事务隔离级别方面的内容,希望对MySql有兴趣的朋友有所帮助。
本文网址链接:http://www.codes51.com/article/detail_1725937_5.html