1
# Test of the READ_ONLY global variable:
2
# check that it blocks updates unless they are only on temporary tables.
4
# should work with embedded server after mysqltest is fixed
5
-- source include/not_embedded.inc
8
DROP TABLE IF EXISTS t1,t2,t3;
11
# READ_ONLY does nothing to SUPER users
12
# so we use a non-SUPER one:
14
grant CREATE, SELECT, DROP on *.* to test@localhost;
16
connect (con1,localhost,test,,test);
20
set global read_only=0;
24
create table t1 (a int);
26
insert into t1 values(1);
28
create table t2 select * from t1;
32
set global read_only=1;
34
# We check that SUPER can:
36
create table t3 (a int);
41
select @@global.read_only;
44
create table t3 (a int);
47
insert into t1 values(1);
49
# if a statement, after parse stage, looks like it will update a
50
# non-temp table, it will be rejected, even if at execution it would
51
# have turned out that 0 rows would be updated
53
update t1 set a=1 where 1=0;
55
# multi-update is special (see sql_parse.cc) so we test it
57
update t1,t2 set t1.a=t2.a+1 where t1.a=t2.a;
59
# check multi-delete to be sure
61
delete t1,t2 from t1,t2 where t1.a=t2.a;
63
# With temp tables updates should be accepted:
65
create temporary table t3 (a int);
67
create temporary table t4 (a int) select * from t3;
69
insert into t3 values(1);
71
insert into t4 select * from t3;
73
# a non-temp table updated:
75
update t1,t3 set t1.a=t3.a+1 where t1.a=t3.a;
77
# no non-temp table updated (just swapped):
78
update t1,t3 set t3.a=t1.a+1 where t1.a=t3.a;
80
update t4,t3 set t4.a=t3.a+1 where t4.a=t3.a;
83
delete t1 from t1,t3 where t1.a=t3.a;
85
delete t3 from t1,t3 where t1.a=t3.a;
87
delete t4 from t3,t4 where t4.a=t3.a;
89
# and even homonymous ones
91
create temporary table t1 (a int);
93
insert into t1 values(1);
95
update t1,t3 set t1.a=t3.a+1 where t1.a=t3.a;
97
delete t1 from t1,t3 where t1.a=t3.a;
102
insert into t1 values(1);
105
# BUG#11733: COMMITs should not happen if read-only is set
108
# LOCK TABLE ... WRITE / READ_ONLY
109
# - is an error in the same connection
110
# - is ok in a different connection
113
set global read_only=0;
120
--error ER_LOCK_OR_ACTIVE_TRANSACTION
121
set global read_only=1;
123
# The following call blocks until con1 releases the write lock.
124
# Blocking is expected.
125
send set global read_only=1;
129
select @@global.read_only;
132
select @@global.read_only;
137
# LOCK TABLE ... READ / READ_ONLY
138
# - is an error in the same connection
139
# - is ok in a different connection
142
set global read_only=0;
149
--error ER_LOCK_OR_ACTIVE_TRANSACTION
150
set global read_only=1;
152
# The following call blocks until con1 releases the read lock.
153
# Blocking is a limitation, and could be improved.
154
send set global read_only=1;
158
select @@global.read_only;
161
select @@global.read_only;
166
# pending transaction / READ_ONLY
167
# - is an error in the same connection
168
# - is ok in a different connection
171
set global read_only=0;
178
--error ER_LOCK_OR_ACTIVE_TRANSACTION
179
set global read_only=1;
181
set global read_only=1;
184
select @@global.read_only;
187
# Verify that FLUSH TABLES WITH READ LOCK do not block READ_ONLY
188
# - in the same SUPER connection
189
# - in another SUPER connection
192
set global read_only=0;
193
flush tables with read lock;
194
set global read_only=1;
197
connect (root2,localhost,root,,test);
200
set global read_only=0;
201
flush tables with read lock;
204
set global read_only=1;
207
select @@global.read_only;
210
# BUG #22077 "DROP TEMPORARY TABLE fails with wrong error if read_only is set"
212
# check if DROP TEMPORARY on a non-existing temporary table returns the right
215
--error ER_BAD_TABLE_ERROR
216
drop temporary table ttt;
218
# check if DROP TEMPORARY TABLE IF EXISTS produces a warning with read_only set
219
drop temporary table if exists ttt;
225
set global read_only=0;
227
drop user test@localhost;
229
--echo # Bug #27440 read_only allows create and drop database
231
set global read_only= 1;
233
drop database if exists mysqltest_db1;
234
drop database if exists mysqltest_db2;
237
delete from mysql.user where User like 'mysqltest_%';
238
delete from mysql.db where User like 'mysqltest_%';
239
delete from mysql.tables_priv where User like 'mysqltest_%';
240
delete from mysql.columns_priv where User like 'mysqltest_%';
243
grant all on mysqltest_db2.* to `mysqltest_u1`@`%`;
244
create database mysqltest_db1;
245
grant all on mysqltest_db1.* to `mysqltest_u1`@`%`;
247
connect (con_bug27440,127.0.0.1,mysqltest_u1,,test,$MASTER_MYPORT,);
248
connection con_bug27440;
249
--error ER_OPTION_PREVENTS_STATEMENT
250
create database mysqltest_db2;
251
show databases like '%mysqltest_db2%';
252
--error ER_OPTION_PREVENTS_STATEMENT
253
drop database mysqltest_db1;
254
disconnect con_bug27440;
256
delete from mysql.user where User like 'mysqltest_%';
257
delete from mysql.db where User like 'mysqltest_%';
258
delete from mysql.tables_priv where User like 'mysqltest_%';
259
delete from mysql.columns_priv where User like 'mysqltest_%';
261
drop database mysqltest_db1;
262
set global read_only=0;