1
# Establish connection con1 (user=root)
2
# Establish connection con2 (user=root)
3
drop table if exists t1,t2;
4
# Switch to connection con1
5
create table t1 (id integer, x integer) engine = InnoDB;
6
insert into t1 values(0, 0);
8
SELECT * from t1 where id = 0 FOR UPDATE;
11
# Switch to connection con2
13
update t1 set x=2 where id = 0;
14
# Switch to connection con1
15
update t1 set x=1 where id = 0;
20
# Switch to connection con2
22
# Switch to connection con1
28
# Switch to connection con1
29
create table t1 (id integer, x integer) engine = InnoDB;
30
create table t2 (b integer, a integer) engine = InnoDB;
31
insert into t1 values(0, 0), (300, 300);
32
insert into t2 values(0, 10), (1, 20), (2, 30);
40
select x from t1 where id=0 FOR UPDATE;
43
update t2 set a=100 where b=(SELECT x from t1 where id = b);
53
# Switch to connection con2
55
update t1 set x=2 where id = 0;
56
# Switch to connection con1
57
update t1 set x=1 where id = 0;
63
# Switch to connection con2
65
# Switch to connection con1
72
create table t1 (id integer, x integer) engine = InnoDB;
73
create table t2 (b integer, a integer) engine = InnoDB;
74
insert into t1 values(0, 0), (300, 300);
75
insert into t2 values(0, 0), (1, 20), (2, 30);
77
# Switch to connection con1
78
select a,b from t2 UNION SELECT id, x from t1 FOR UPDATE;
93
# Switch to connection con2
94
update t2 set a=2 where b = 0;
100
update t1 set x=2 where id = 0;
101
# Switch to connection con1
102
update t1 set x=1 where id = 0;
108
# Switch to connection con2
110
# Switch to connection con1
116
# Switch to connection default + disconnect con1 and con2
119
set storage_engine=innodb;
120
drop table if exists a;
121
drop table if exists A;
122
create table A (c int);
123
insert into A (c) values (0);
124
create table a as select * from A;
126
drop table if exists a;
127
set storage_engine=default;