1
# Test of the READ_ONLY global variable:
2
# check that it blocks updates unless they are only on temporary tables.
5
DROP TABLE IF EXISTS t1,t2,t3;
8
# READ_ONLY does nothing to SUPER users
9
# so we use a non-SUPER one:
11
connect (con1,localhost,test,,test);
15
set global read_only=0;
19
create table t1 (a int);
21
insert into t1 values(1);
23
create table t2 select * from t1;
27
set global read_only=1;
29
# We check that SUPER can:
31
create table t3 (a int);
36
select @@global.read_only;
39
create table t3 (a int);
42
insert into t1 values(1);
44
# if a statement, after parse stage, looks like it will update a
45
# non-temp table, it will be rejected, even if at execution it would
46
# have turned out that 0 rows would be updated
48
update t1 set a=1 where 1=0;
50
# multi-update is special (see sql_parse.cc) so we test it
52
update t1,t2 set t1.a=t2.a+1 where t1.a=t2.a;
54
# check multi-delete to be sure
56
delete t1,t2 from t1,t2 where t1.a=t2.a;
58
# With temp tables updates should be accepted:
60
create temporary table t3 (a int);
62
create temporary table t4 (a int) select * from t3;
64
insert into t3 values(1);
66
insert into t4 select * from t3;
68
# a non-temp table updated:
70
update t1,t3 set t1.a=t3.a+1 where t1.a=t3.a;
72
# no non-temp table updated (just swapped):
73
update t1,t3 set t3.a=t1.a+1 where t1.a=t3.a;
75
update t4,t3 set t4.a=t3.a+1 where t4.a=t3.a;
78
delete t1 from t1,t3 where t1.a=t3.a;
80
delete t3 from t1,t3 where t1.a=t3.a;
82
delete t4 from t3,t4 where t4.a=t3.a;
84
# and even homonymous ones
86
create temporary table t1 (a int);
88
insert into t1 values(1);
90
update t1,t3 set t1.a=t3.a+1 where t1.a=t3.a;
92
delete t1 from t1,t3 where t1.a=t3.a;
97
insert into t1 values(1);
100
# BUG#11733: COMMITs should not happen if read-only is set
103
# LOCK TABLE ... WRITE / READ_ONLY
104
# - is an error in the same connection
105
# - is ok in a different connection
108
set global read_only=0;
115
--error ER_LOCK_OR_ACTIVE_TRANSACTION
116
set global read_only=1;
118
# The following call blocks until con1 releases the write lock.
119
# Blocking is expected.
120
send set global read_only=1;
124
select @@global.read_only;
127
select @@global.read_only;
132
# LOCK TABLE ... READ / READ_ONLY
133
# - is an error in the same connection
134
# - is ok in a different connection
137
set global read_only=0;
144
--error ER_LOCK_OR_ACTIVE_TRANSACTION
145
set global read_only=1;
147
# The following call blocks until con1 releases the read lock.
148
# Blocking is a limitation, and could be improved.
149
send set global read_only=1;
153
select @@global.read_only;
156
select @@global.read_only;
161
# pending transaction / READ_ONLY
162
# - is an error in the same connection
163
# - is ok in a different connection
166
set global read_only=0;
173
--error ER_LOCK_OR_ACTIVE_TRANSACTION
174
set global read_only=1;
176
set global read_only=1;
179
select @@global.read_only;
182
# Verify that FLUSH TABLES WITH READ LOCK do not block READ_ONLY
183
# - in the same SUPER connection
184
# - in another SUPER connection
187
set global read_only=0;
188
flush tables with read lock;
189
set global read_only=1;
192
connect (root2,localhost,root,,test);
195
set global read_only=0;
196
flush tables with read lock;
199
set global read_only=1;
202
select @@global.read_only;
205
# BUG #22077 "DROP TEMPORARY TABLE fails with wrong error if read_only is set"
207
# check if DROP TEMPORARY on a non-existing temporary table returns the right
210
--error ER_BAD_TABLE_ERROR
211
drop temporary table ttt;
213
# check if DROP TEMPORARY TABLE IF EXISTS produces a warning with read_only set
214
drop temporary table if exists ttt;
220
set global read_only=0;
222
drop user test@localhost;
224
--echo # Bug #27440 read_only allows create and drop database
226
set global read_only= 1;
228
drop database if exists mysqltest_db1;
229
drop database if exists mysqltest_db2;
232
delete from mysql.user where User like 'mysqltest_%';
233
delete from mysql.db where User like 'mysqltest_%';
234
delete from mysql.tables_priv where User like 'mysqltest_%';
235
delete from mysql.columns_priv where User like 'mysqltest_%';
238
grant all on mysqltest_db2.* to `mysqltest_u1`@`%`;
239
create database mysqltest_db1;
240
grant all on mysqltest_db1.* to `mysqltest_u1`@`%`;
242
connect (con_bug27440,127.0.0.1,mysqltest_u1,,test,$MASTER_MYPORT,);
243
connection con_bug27440;
244
--error ER_OPTION_PREVENTS_STATEMENT
245
create database mysqltest_db2;
246
show databases like '%mysqltest_db2%';
247
--error ER_OPTION_PREVENTS_STATEMENT
248
drop database mysqltest_db1;
249
disconnect con_bug27440;
251
delete from mysql.user where User like 'mysqltest_%';
252
delete from mysql.db where User like 'mysqltest_%';
253
delete from mysql.tables_priv where User like 'mysqltest_%';
254
delete from mysql.columns_priv where User like 'mysqltest_%';
256
drop database mysqltest_db1;
257
set global read_only=0;