博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【练习】使用事务和锁定语句
阅读量:5222 次
发布时间:2019-06-14

本文共 5790 字,大约阅读时间需要 19 分钟。

1.在mysql客户机会话中,检查当前隔离级别。

2.使用PROMPT语句,将上一步打开的mysql会话中提示符改为t1,以便将其与后面的客户机会话区别开来。

3.在t1 mysql会话中启动一个新事务。

4.在t1会话中,选择city表中的ID>4070的所有行。

5.在另一个终端窗口中打开第二个mysql会话,将该mysql会话中的提示符更改为t2

6.在t2会话中,启动一个新事务,选择city表中的ID>4070的所有行。

7.在t2会话中,向city表中插入新的一行,确认新行已经加入。

 

1.

mysql> select @@global.tx_isolation;+-----------------------+| @@global.tx_isolation |+-----------------------+| REPEATABLE-READ       |+-----------------------+1 row in set (0.00 sec)

2.

mysql> prompt t1>;PROMPT set to 't1>'t1>start transaction;Query OK, 0 rows affected (0.00 sec)

3.

t1>use worldReading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changed

4.

t1>select * from city where id >4070;+------+--------------+-------------+------------+------------+| ID   | Name         | CountryCode | District   | Population |+------+--------------+-------------+------------+------------+| 4071 | Mount Darwin | ZWE         | Harare     |     164362 || 4072 | Mutare       | ZWE         | Manicaland |     131367 || 4073 | Gweru        | ZWE         | Midlands   |     128037 || 4074 | Gaza         | PSE         | Gaza       |     353632 || 4075 | Khan Yunis   | PSE         | Khan Yunis |     123175 || 4076 | Hebron       | PSE         | Hebron     |     119401 || 4077 | Jabaliya     | PSE         | North Gaza |     113901 || 4078 | Nablus       | PSE         | Nablus     |     100231 || 4079 | Rafah        | PSE         | Rafah      |      92020 |+------+--------------+-------------+------------+------------+9 rows in set (0.00 sec)

5.

t1>prompt t2>;PROMPT set to 't2>'t2>t2>start transaction;Query OK, 0 rows affected (0.00 sec)

6.

t2>use world;Database changedt2>select * from city where id >4070;+------+--------------+-------------+------------+------------+| ID   | Name         | CountryCode | District   | Population |+------+--------------+-------------+------------+------------+| 4071 | Mount Darwin | ZWE         | Harare     |     164362 || 4072 | Mutare       | ZWE         | Manicaland |     131367 || 4073 | Gweru        | ZWE         | Midlands   |     128037 || 4074 | Gaza         | PSE         | Gaza       |     353632 || 4075 | Khan Yunis   | PSE         | Khan Yunis |     123175 || 4076 | Hebron       | PSE         | Hebron     |     119401 || 4077 | Jabaliya     | PSE         | North Gaza |     113901 || 4078 | Nablus       | PSE         | Nablus     |     100231 || 4079 | Rafah        | PSE         | Rafah      |      92020 |+------+--------------+-------------+------------+------------+9 rows in set (0.00 sec)

7.

t2>insert into city (name,countrycode) values ('new city','ata');Query OK, 1 row affected (0.00 sec)t2>select * from city where id >4070;+------+--------------+-------------+------------+------------+| ID   | Name         | CountryCode | District   | Population |+------+--------------+-------------+------------+------------+| 4071 | Mount Darwin | ZWE         | Harare     |     164362 || 4072 | Mutare       | ZWE         | Manicaland |     131367 || 4073 | Gweru        | ZWE         | Midlands   |     128037 || 4074 | Gaza         | PSE         | Gaza       |     353632 || 4075 | Khan Yunis   | PSE         | Khan Yunis |     123175 || 4076 | Hebron       | PSE         | Hebron     |     119401 || 4077 | Jabaliya     | PSE         | North Gaza |     113901 || 4078 | Nablus       | PSE         | Nablus     |     100231 || 4079 | Rafah        | PSE         | Rafah      |      92020 || 4080 | new city     | ata         |            |          0 |+------+--------------+-------------+------------+------------+10 rows in set (0.00 sec)

8.

t2>prompt t1>;PROMPT set to 't1>'t1>start transaction;Query OK, 0 rows affected (0.01 sec)t1>commit;Query OK, 0 rows affected (0.00 sec)

9.

t1>select * from city where id >4070;+------+--------------+-------------+------------+------------+| ID   | Name         | CountryCode | District   | Population |+------+--------------+-------------+------------+------------+| 4071 | Mount Darwin | ZWE         | Harare     |     164362 || 4072 | Mutare       | ZWE         | Manicaland |     131367 || 4073 | Gweru        | ZWE         | Midlands   |     128037 || 4074 | Gaza         | PSE         | Gaza       |     353632 || 4075 | Khan Yunis   | PSE         | Khan Yunis |     123175 || 4076 | Hebron       | PSE         | Hebron     |     119401 || 4077 | Jabaliya     | PSE         | North Gaza |     113901 || 4078 | Nablus       | PSE         | Nablus     |     100231 || 4079 | Rafah        | PSE         | Rafah      |      92020 || 4080 | new city     | ata         |            |          0 |+------+--------------+-------------+------------+------------+10 rows in set (0.01 sec)

10.

t1>start transaction;Query OK, 0 rows affected (0.00 sec)t1>delete from city where id =4080;Query OK, 1 row affected (0.00 sec)t1>select * from city where id >4070;+------+--------------+-------------+------------+------------+| ID   | Name         | CountryCode | District   | Population |+------+--------------+-------------+------------+------------+| 4071 | Mount Darwin | ZWE         | Harare     |     164362 || 4072 | Mutare       | ZWE         | Manicaland |     131367 || 4073 | Gweru        | ZWE         | Midlands   |     128037 || 4074 | Gaza         | PSE         | Gaza       |     353632 || 4075 | Khan Yunis   | PSE         | Khan Yunis |     123175 || 4076 | Hebron       | PSE         | Hebron     |     119401 || 4077 | Jabaliya     | PSE         | North Gaza |     113901 || 4078 | Nablus       | PSE         | Nablus     |     100231 || 4079 | Rafah        | PSE         | Rafah      |      92020 |+------+--------------+-------------+------------+------------+9 rows in set (0.00 sec)

 

转载于:https://www.cnblogs.com/tomatoes-/p/6024578.html

你可能感兴趣的文章
SQL Server 如何查询表定义的列和索引信息
查看>>
GCD 之线程死锁
查看>>
NoSQL数据库常见分类
查看>>
一题多解 之 Bat
查看>>
Java 内部类
查看>>
{面试题7: 使用两个队列实现一个栈}
查看>>
前端开发就从认识浏览器开始 - 浏览器处理请求的过程
查看>>
【练习】使用事务和锁定语句
查看>>
centos7升级firefox的flash插件
查看>>
jmeter系列二(jmeter engine相关)
查看>>
一份超全超详细的 ADB 用法大全
查看>>
Spring定时任务(@Scheduled)
查看>>
WebView 调试
查看>>
IB使用
查看>>
Linux硬链接和软链接(符号链接)
查看>>
git stash
查看>>
Apache Common-IO 使用
查看>>
Java-第一课正则表达式
查看>>
深入剖析,什么是eval的直接调用.
查看>>
apidoc
查看>>