1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617
|
# Skipping the test when binlog format is mix/statement due to Bug#22173401
--source include/have_binlog_format_row.inc
# Test of the READ_ONLY global variable:
# check that it blocks updates unless they are only on temporary tables.
set @start_read_only= @@global.read_only;
# Save the initial number of concurrent sessions
--source include/count_sessions.inc
--disable_warnings
DROP TABLE IF EXISTS t1,t2,t3;
--enable_warnings
# READ_ONLY does nothing to SUPER users
# so we use a non-SUPER one:
set @orig_sql_mode= @@sql_mode;
create user test@localhost;
grant CREATE, SELECT, DROP on *.* to test@localhost;
--echo connect (con1,localhost,test,,test);
connect (con1,localhost,test,,test);
--echo connection default;
connection default;
set global read_only=0;
--echo connection con1;
connection con1;
create table t1 (a int);
insert into t1 values(1);
create table t2 select * from t1;
--echo connection default;
connection default;
set global read_only=1;
# We check that SUPER can:
create table t3 (a int);
drop table t3;
--echo connection con1;
connection con1;
select @@global.read_only;
--error ER_OPTION_PREVENTS_STATEMENT
create table t3 (a int);
--error ER_OPTION_PREVENTS_STATEMENT
insert into t1 values(1);
# if a statement, after parse stage, looks like it will update a
# non-temp table, it will be rejected, even if at execution it would
# have turned out that 0 rows would be updated
--error ER_OPTION_PREVENTS_STATEMENT
update t1 set a=1 where 1=0;
# multi-update is special (see sql_parse.cc) so we test it
--error ER_OPTION_PREVENTS_STATEMENT
update t1,t2 set t1.a=t2.a+1 where t1.a=t2.a;
# check multi-delete to be sure
--error ER_OPTION_PREVENTS_STATEMENT
delete t1,t2 from t1,t2 where t1.a=t2.a;
# With temp tables updates should be accepted:
create temporary table t3 (a int);
create temporary table t4 (a int) select * from t3;
insert into t3 values(1);
insert into t4 select * from t3;
# a non-temp table updated:
--error ER_OPTION_PREVENTS_STATEMENT
update t1,t3 set t1.a=t3.a+1 where t1.a=t3.a;
# no non-temp table updated (just swapped):
update t1,t3 set t3.a=t1.a+1 where t1.a=t3.a;
update t4,t3 set t4.a=t3.a+1 where t4.a=t3.a;
--error ER_OPTION_PREVENTS_STATEMENT
delete t1 from t1,t3 where t1.a=t3.a;
delete t3 from t1,t3 where t1.a=t3.a;
delete t4 from t3,t4 where t4.a=t3.a;
# and even homonymous ones
create temporary table t1 (a int);
insert into t1 values(1);
update t1,t3 set t1.a=t3.a+1 where t1.a=t3.a;
delete t1 from t1,t3 where t1.a=t3.a;
drop table t1;
--error ER_OPTION_PREVENTS_STATEMENT
insert into t1 values(1);
#
# Bug#11733 COMMITs should not happen if read-only is set
#
# LOCK TABLE ... WRITE / READ_ONLY
# - is an error in the same connection
# - is ok in a different connection
--echo connection default;
connection default;
set global read_only=0;
lock table t1 write;
--echo connection con1;
connection con1;
lock table t2 write;
--echo connection default;
connection default;
--error ER_LOCK_OR_ACTIVE_TRANSACTION
set global read_only=1;
unlock tables ;
# The following call blocks until con1 releases the write lock.
# Blocking is expected.
--echo send set global read_only=1;
send set global read_only=1;
--echo connection con1;
connection con1;
select @@global.read_only;
unlock tables ;
let $wait_condition= SELECT @@global.read_only= 1;
--source include/wait_condition.inc
select @@global.read_only;
--echo connection default;
connection default;
--echo reap;
reap;
# LOCK TABLE ... READ / READ_ONLY
# - is an error in the same connection
# - is ok in a different connection
--echo connection default;
connection default;
set global read_only=0;
lock table t1 read;
--echo connection con1;
connection con1;
lock table t2 read;
--echo connection default;
connection default;
--error ER_LOCK_OR_ACTIVE_TRANSACTION
set global read_only=1;
unlock tables ;
# after unlock tables in current connection
# the next command must be executed successfully
set global read_only=1;
select @@global.read_only;
--echo connection con1;
connection con1;
select @@global.read_only;
unlock tables ;
--echo connection default;
connection default;
# pending transaction / READ_ONLY
# - is an error in the same connection
# - is ok in a different connection
--echo connection default;
connection default;
set global read_only=0;
BEGIN;
--echo connection con1;
connection con1;
BEGIN;
--echo connection default;
connection default;
--error ER_LOCK_OR_ACTIVE_TRANSACTION
set global read_only=1;
ROLLBACK;
set global read_only=1;
--echo connection con1;
connection con1;
select @@global.read_only;
ROLLBACK;
# Verify that FLUSH TABLES WITH READ LOCK do not block READ_ONLY
# - in the same SUPER connection
# - in another SUPER connection
--echo connection default;
connection default;
set global read_only=0;
flush tables with read lock;
set global read_only=1;
unlock tables;
--echo connect (root2,localhost,root,,test);
connect (root2,localhost,root,,test);
--echo connection default;
connection default;
set global read_only=0;
flush tables with read lock;
--echo connection root2;
connection root2;
set global read_only=1;
--echo connection default;
connection default;
select @@global.read_only;
unlock tables;
disconnect root2;
# Bug#22077 DROP TEMPORARY TABLE fails with wrong error if read_only is set
#
# check if DROP TEMPORARY on a non-existing temporary table returns the right
# error
--error ER_BAD_TABLE_ERROR
drop temporary table ttt;
# check if DROP TEMPORARY TABLE IF EXISTS produces a warning with read_only set
drop temporary table if exists ttt;
#
# Cleanup
#
--echo connection default;
connection default;
set global read_only=0;
disconnect con1;
drop table t1,t2;
drop user test@localhost;
--echo #
--echo # Bug#27440 read_only allows create and drop database
--echo #
set global read_only= 1;
--disable_warnings
drop database if exists mysqltest_db1;
drop database if exists mysqltest_db2;
--enable_warnings
delete from mysql.user where User like 'mysqltest_%';
delete from mysql.db where User like 'mysqltest_%';
delete from mysql.tables_priv where User like 'mysqltest_%';
delete from mysql.columns_priv where User like 'mysqltest_%';
flush privileges;
create user `mysqltest_u1`@`%`;
grant all on mysqltest_db2.* to `mysqltest_u1`@`%`;
create database mysqltest_db1;
grant all on mysqltest_db1.* to `mysqltest_u1`@`%`;
flush privileges;
--echo connect (con_bug27440,127.0.0.1,mysqltest_u1,,test,MASTER_MYPORT,);
connect (con_bug27440,127.0.0.1,mysqltest_u1,,test,$MASTER_MYPORT,);
--echo connection con_bug27440;
connection con_bug27440;
--error ER_OPTION_PREVENTS_STATEMENT
create database mysqltest_db2;
show databases like '%mysqltest_db2%';
--error ER_OPTION_PREVENTS_STATEMENT
drop database mysqltest_db1;
--echo disconnect con_bug27440;
disconnect con_bug27440;
--echo connection default;
connection default;
delete from mysql.user where User like 'mysqltest_%';
delete from mysql.db where User like 'mysqltest_%';
delete from mysql.tables_priv where User like 'mysqltest_%';
delete from mysql.columns_priv where User like 'mysqltest_%';
flush privileges;
drop database mysqltest_db1;
set global read_only= @start_read_only;
--echo #
--echo # WL#5968 Implement START TRANSACTION READ (WRITE|ONLY);
--echo #
--echo #
--echo # Test interaction with read_only system variable.
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
CREATE TABLE t1(a INT);
INSERT INTO t1 VALUES (1), (2);
CREATE USER user1;
connect (con1, localhost, user1);
connection default;
SET GLOBAL read_only= 1;
--echo # All allowed with super privilege
START TRANSACTION;
COMMIT;
START TRANSACTION READ ONLY;
COMMIT;
START TRANSACTION READ WRITE;
COMMIT;
--echo # We allow implicit RW transaction without super privilege
--echo # for compatibility reasons
connection con1;
START TRANSACTION;
--echo # Check that table updates are still disallowed.
--error ER_OPTION_PREVENTS_STATEMENT
INSERT INTO t1 VALUES (3);
--error ER_OPTION_PREVENTS_STATEMENT
UPDATE t1 SET a= 1;
--error ER_OPTION_PREVENTS_STATEMENT
DELETE FROM t1;
COMMIT;
START TRANSACTION READ ONLY;
COMMIT;
--echo # Explicit RW trans is not allowed without super privilege
--error ER_OPTION_PREVENTS_STATEMENT
START TRANSACTION READ WRITE;
COMMIT;
disconnect con1;
--source include/wait_until_disconnected.inc
connection default;
DROP USER user1;
SET GLOBAL read_only= 0;
DROP TABLE t1;
set sql_mode= @orig_sql_mode;
--echo #
--echo # Bug#28490368 INNODB: ASSERTION FAILURE: DICT0DD.CC:1071:!FAIL
--echo #
CREATE TABLE t1(f1 INT);
CREATE TEMPORARY TABLE t1(a1 INT);
CREATE TEMPORARY TABLE t3(a3 INT);
SET @@global.super_read_only=TRUE;
# Without the fix, the RENAME TABLE asserts in innodb, as innodb expects us
# to not request update operation in super_read_only mode.
--error ER_OPTION_PREVENTS_STATEMENT
RENAME TABLE t1 to t3;
SET @@global.read_only=default;
DROP TABLE t1;
DROP TABLE t1;
DROP TABLE t3;
--echo #
--echo # BUG#28438114: SET READ_ONLY=1 SOMETIMES DOESN'T BLOCK CONCURRENT DDL.
--echo #
--echo # Prepare the sql file for testing DDLS.
SET @save_read_only= @@global.read_only;
CREATE USER test@localhost;
GRANT CREATE, DROP, INSERT, CREATE TABLESPACE, ALTER ROUTINE, FILE, RELOAD ON *.* TO test@localhost;
--echo connect (con1,localhost,test,,test);
connect (con1,localhost,test,,test);
--echo connect (con2,localhost,root,,test);
connect (con2,localhost,root,,test);
--echo # Test CREATE DATABASE statement.
let $query= CREATE DATABASE new;
--source include/read_only_bug28438114.inc
--echo # Test ALTER DATABASE statement
--let query= ALTER DATABASE test CHARACTER SET utf8;
--source include/read_only_bug28438114.inc
CREATE DATABASE new;
--echo # Test CREATE DATABASE statement which doesn't update DD tables.
--let query= CREATE DATABASE IF NOT EXISTS new;
--source include/read_only_bug28438114.inc
--echo # Test DROP DATABASE statement.
let $query= DROP DATABASE new;
--source include/read_only_bug28438114.inc
DROP DATABASE new;
--echo # Test CREATE TABLE statement.
let $query= CREATE TABLE t1(fld1 INT);
--source include/read_only_bug28438114.inc
--echo # Test CREATE TABLE which doesn't update update DD tables.
CREATE TABLE t1(fld1 INT);
let $query= CREATE TABLE IF NOT EXISTS t1(fld1 INT);
--source include/read_only_bug28438114.inc
--echo # Test ALTER TABLE statement.
let $query= ALTER TABLE t1 ADD fld2 INT;
--source include/read_only_bug28438114.inc
--echo # Test ALTER TABLE statement which doesn't update DD tables
ALTER TABLE t1 RENAME COLUMN fld1 TO fld1;
--source include/read_only_bug28438114.inc
--echo # Test DROP TABLE statement.
let $query= DROP TABLE t1;
--source include/read_only_bug28438114.inc
--echo # Test DROP TABLE statement which doesn't update DD tables.
let $query= DROP TABLE IF EXISTS no_such_table;
--source include/read_only_bug28438114.inc
--echo # Test CREATE INDEX statement.
let $query= CREATE INDEX idx1 ON t1 (fld1) USING BTREE;
--source include/read_only_bug28438114.inc
--echo # Test DROP INDEX statement.
CREATE INDEX idx1 ON t1 (fld1) USING BTREE;
let $query= DROP INDEX idx1 ON t1;
--source include/read_only_bug28438114.inc
DROP INDEX idx1 ON t1;
--echo # Test IMPORT TABLE statement.
--echo # Setup test environment.
let $MYSQLD_DATADIR=`SELECT @@datadir`;
--perl
chdir $ENV{'MYSQL_TMP_DIR'};
mkdir "export";
EOF
let $EXPORT_DIR= $MYSQL_TMP_DIR/export;
let $MYSQLD_DATADIR=`SELECT @@datadir`;
CREATE TABLE t2(fld1 INT) ENGINE=MYISAM;
FLUSH TABLES WITH READ LOCK;
--copy_files_wildcard $MYSQLD_DATADIR/test/ $EXPORT_DIR t2*
UNLOCK TABLES;
DROP TABLE t2;
--copy_files_wildcard $EXPORT_DIR $MYSQLD_DATADIR/test/ t2*
let $query= IMPORT TABLE FROM 'test/t2*.sdi';
--source include/read_only_bug28438114.inc
--force-rmdir $EXPORT_DIR
--echo # Test CREATE TRIGGER statement.
let $query= CREATE TRIGGER trg1 BEFORE INSERT ON t1
FOR EACH ROW BEGIN END;
--source include/read_only_bug28438114.inc
--echo # Test DROP TRIGGER statement.
CREATE TRIGGER trg1 BEFORE INSERT ON t1
FOR EACH ROW BEGIN END;
let $query= DROP TRIGGER trg1;
--source include/read_only_bug28438114.inc
DROP TRIGGER trg1;
--echo # Test TRUNCATE TABLE statement.
let $query= TRUNCATE TABLE t1;
--source include/read_only_bug28438114.inc
--echo # Test CREATE VIEW statement.
let $query= CREATE VIEW v1 AS SELECT * FROM t1;
--source include/read_only_bug28438114.inc
--echo # Test ALTER VIEW statement.
CREATE VIEW v1 AS SELECT * FROM t1;
let $query= ALTER VIEW v1 AS SELECT 1;
--source include/read_only_bug28438114.inc
--echo # Test DROP VIEW statement.
let $query= DROP VIEW v1;
--source include/read_only_bug28438114.inc
--echo # Test DROP VIEW statement which doesn't update DD tables.
let $query= DROP VIEW IF EXISTS no_such_view;
--source include/read_only_bug28438114.inc
DROP VIEW v1;
DROP TABLE t1;
--echo # Test CREATE TABLESPACE statement
let $query= CREATE TABLESPACE ts1
ADD DATAFILE 'ts1.ibd' ENGINE=INNODB;
--source include/read_only_bug28438114.inc
CREATE TABLESPACE ts1 ADD DATAFILE 'ts1.ibd' ENGINE=INNODB;
--echo # Test DROP TABLESPACE statement
let $query= DROP TABLESPACE ts1;
--source include/read_only_bug28438114.inc
DROP TABLESPACE ts1;
--echo # Test CREATE FUNCTION statement.
let $query= CREATE FUNCTION f1() RETURNS INT RETURN 5;
--source include/read_only_bug28438114.inc
--echo # Test ALTER FUNCTION statement.
CREATE FUNCTION f1() RETURNS INT RETURN 5;
let $query= ALTER FUNCTION f1 COMMENT 'test';
--source include/read_only_bug28438114.inc
--echo # Test DROP FUNCTION statement.
let $query= DROP FUNCTION f1;
--source include/read_only_bug28438114.inc
--echo # Test DROP FUNCTION statement which doesn't update DD tables.
let $query= DROP FUNCTION IF EXISTS f1;
--source include/read_only_bug28438114.inc
DROP FUNCTION f1;
--echo # Test CREATE PROCEDURE statement
let $query= CREATE PROCEDURE p1() select 1;
--source include/read_only_bug28438114.inc
--echo # Test ALTER PROCEDURE statement.
CREATE PROCEDURE p1() select 1;
let $query= ALTER PROCEDURE p1 comment 'test';
--source include/read_only_bug28438114.inc
--echo # Test DROP PROCEDURE statement.
let $query= DROP PROCEDURE p1;
--source include/read_only_bug28438114.inc
--echo # Test DROP PROCEDURE statement which doesn't update DD tables.
let $query= DROP PROCEDURE IF EXISTS no_such_procedure;
--source include/read_only_bug28438114.inc
DROP PROCEDURE p1;
--echo # Test CREATE EVENT statement
SET @saved_event_scheduler= @@global.event_scheduler;
SET GLOBAL event_scheduler= OFF;
let $query= CREATE EVENT event1 ON SCHEDULE
EVERY 10 HOUR DO SELECT 1;
--source include/read_only_bug28438114.inc
--echo # Test CREATE EVENT statement which doesn't update DD tables
CREATE EVENT event1 ON SCHEDULE EVERY 10 HOUR DO SELECT 1;
let $query= CREATE EVENT IF NOT EXISTS event1 ON SCHEDULE EVERY 10 HOUR DO SELECT 1;
--source include/read_only_bug28438114.inc
--echo # Test ALTER EVENT statement
let $query= ALTER EVENT event1 DISABLE;
--source include/read_only_bug28438114.inc
--echo # Test DROP EVENT statement.
let $query= DROP EVENT event1;
--source include/read_only_bug28438114.inc
DROP EVENT event1;
--echo # Test DROP EVENT statement which doesn't update DD tables
let $query= DROP EVENT IF EXISTS no_such_event;
--source include/read_only_bug28438114.inc
SET GLOBAL event_scheduler= @saved_event_scheduler;
--echo # Test case added for coverage.
CREATE TABLE t1(fld1 INT);
connection con1;
--echo # FTWRL and FLUSH TABLE..FOR EXPORT is not blocked
--echo # in read_only/super_read_only mode.
FLUSH TABLES t1 WITH READ LOCK;
UNLOCK TABLES;
FLUSH TABLES t1 FOR EXPORT;
UNLOCK TABLES;
--echo # Clean up.
connection default;
DROP TABLE t1;
DROP USER test@localhost;
SET GLOBAL read_only= @save_read_only;
--remove_files_wildcard $MYSQLD_DATADIR/test t2*
--disconnect con1
--disconnect con2
--echo #
--echo # BUG#30274240: ALTER INSTANCE ROTATE INNODB MASTER KEY NOT
--echo # BLOCKED IN READ_ONLY/SUPER_READ_ONLY
SET @save_read_only= @@global.read_only;
SET @save_super_read_only= @@global.super_read_only;
--enable_connect_log
connection default;
CREATE USER user1@localhost;
GRANT ENCRYPTION_KEY_ADMIN ON *.* TO user1@localhost;
--echo connect (con1,localhost,user1,,test);
--echo # This is used by read_only_bug28438114.inc
connect (con1,localhost,user1,,test);
--echo connect (con2,localhost,root,,test);
connect (con2,localhost,root,,test);
--echo # Test ALTER INSTANCE ROTATE INNODB MATER KEY in READ_ONLY mode.
--echo # Reports error with patch.
let $query= ALTER INSTANCE ROTATE INNODB MASTER KEY;
--source include/read_only_bug28438114.inc
--echo # Test ALTER INSTANCE ROTATE INNODB MATER KEY in SUPER_READ_ONLY mode
SET GLOBAL SUPER_READ_ONLY= ON;
--echo # Reports error with patch.
--error ER_OPTION_PREVENTS_STATEMENT
ALTER INSTANCE ROTATE INNODB MASTER KEY;
--echo # Clean up.
connection default;
SET GLOBAL read_only= @save_read_only;
SET GLOBAL super_read_only= @save_super_read_only;
DROP USER user1@localhost;
--disconnect con1
--disconnect con2
# Wait till all disconnects are completed
--source include/wait_until_count_sessions.inc
|