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
update t2 set a=100 where b=(SELECT x from t1 where id = b FOR UPDATE);
50
# Switch to connection con2
52
update t1 set x=2 where id = 0;
53
# Switch to connection con1
54
update t1 set x=1 where id = 0;
60
# Switch to connection con2
62
# Switch to connection con1
69
create table t1 (id integer, x integer) engine = InnoDB;
70
create table t2 (b integer, a integer) engine = InnoDB;
71
insert into t1 values(0, 0), (300, 300);
72
insert into t2 values(0, 0), (1, 20), (2, 30);
74
# Switch to connection con1
75
select a,b from t2 UNION SELECT id, x from t1 FOR UPDATE;
90
# Switch to connection con2
91
update t2 set a=2 where b = 0;
97
update t1 set x=2 where id = 0;
98
# Switch to connection con1
99
update t1 set x=1 where id = 0;
105
# Switch to connection con2
107
# Switch to connection con1
113
# Switch to connection default + disconnect con1 and con2
116
set storage_engine=innodb;
117
drop table if exists a;
118
drop table if exists A;
119
create table A (c int);
120
insert into A (c) values (0);
121
create table a as select * from A;
123
drop table if exists a;
124
set storage_engine=default;