1include/master-slave.inc 2Warnings: 3Note #### Sending passwords in plain text without SSL/TLS is extremely insecure. 4Note #### Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information. 5[connection master] 6call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); 7call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); 8SET @@session.binlog_direct_non_transactional_updates= FALSE; 9CREATE DATABASE replicate_do_db; 10CREATE DATABASE binlog_ignore_db; 11USE replicate_do_db; 12CREATE TABLE replicate_do_db.t1 (a INT) ENGINE=InnoDB; 13CREATE TABLE replicate_do_db.t2 (s CHAR(255)) ENGINE=MyISAM; 14include/sync_slave_sql_with_master.inc 15include/stop_slave.inc 16[connection master] 17CREATE PROCEDURE replicate_do_db.p1 () 18BEGIN 19INSERT INTO t1 VALUES (1); 20INSERT INTO t1 VALUES (2); 21INSERT INTO t1 VALUES (3); 22INSERT INTO t1 VALUES (4); 23INSERT INTO t1 VALUES (5); 24END// 25CREATE PROCEDURE replicate_do_db.p2 () 26BEGIN 27INSERT INTO t1 VALUES (6); 28INSERT INTO t1 VALUES (7); 29INSERT INTO t1 VALUES (8); 30INSERT INTO t1 VALUES (9); 31INSERT INTO t1 VALUES (10); 32INSERT INTO t2 VALUES ('executed replicate_do_db.p2()'); 33END// 34INSERT INTO replicate_do_db.t2 VALUES ('before call replicate_do_db.p1()'); 35USE test; 36BEGIN; 37CALL replicate_do_db.p1(); 38COMMIT; 39INSERT INTO replicate_do_db.t2 VALUES ('after call replicate_do_db.p1()'); 40SELECT * FROM replicate_do_db.t1; 41a 421 432 443 454 465 47SELECT * FROM replicate_do_db.t2; 48s 49before call replicate_do_db.p1() 50after call replicate_do_db.p1() 51[connection slave] 52START SLAVE UNTIL MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=MASTER_POS; 53include/wait_for_slave_sql_to_stop.inc 54include/assert.inc [Slave should have stopped after executing the stored procedure transaction] 55SELECT * from replicate_do_db.t1; 56a 571 582 593 604 615 62SELECT * from replicate_do_db.t2; 63s 64before call replicate_do_db.p1() 65[connection master] 66INSERT INTO replicate_do_db.t2 VALUES ('before call replicate_do_db.p2()'); 67BEGIN; 68CALL replicate_do_db.p2(); 69Warnings: 70Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it accesses a non-transactional table after accessing a transactional table within the same transaction. 71ROLLBACK; 72INSERT INTO replicate_do_db.t2 VALUES ('after call replicate_do_db.p2()'); 73SELECT * FROM replicate_do_db.t1; 74a 751 762 773 784 795 80SELECT * FROM replicate_do_db.t2; 81s 82before call replicate_do_db.p1() 83after call replicate_do_db.p1() 84before call replicate_do_db.p2() 85executed replicate_do_db.p2() 86after call replicate_do_db.p2() 87[connection slave] 88START SLAVE UNTIL MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=MASTER_POS; 89include/wait_for_slave_sql_to_stop.inc 90include/assert.inc [Slave should have stopped after executing the stored procedure transaction] 91SELECT * from replicate_do_db.t1; 92a 931 942 953 964 975 98SELECT * from replicate_do_db.t2; 99s 100before call replicate_do_db.p1() 101executed replicate_do_db.p2() 102START SLAVE; 103include/wait_for_slave_sql_to_start.inc 104# 105# SAVEPOINT and ROLLBACK TO have the same problem in BUG#43263 106# This was reported by BUG#50407 107[connection master] 108BEGIN; 109INSERT INTO replicate_do_db.t1 VALUES(20); 110# 111# Verify whether this statement is binlogged correctly 112/*comment*/ SAVEPOINT has_comment; 113USE replicate_do_db; 114INSERT INTO replicate_do_db.t1 VALUES(30); 115INSERT INTO replicate_do_db.t2 VALUES("in savepoint has_comment"); 116Warnings: 117Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it accesses a non-transactional table after accessing a transactional table within the same transaction. 118USE binlog_ignore_db; 119SavePoint mixed_cases; 120USE replicate_do_db; 121INSERT INTO replicate_do_db.t2 VALUES("in savepoint mixed_cases"); 122Warnings: 123Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it accesses a non-transactional table after accessing a transactional table within the same transaction. 124INSERT INTO replicate_do_db.t1 VALUES(40); 125USE binlog_ignore_db; 126ROLLBACK TO mixed_cases; 127Warnings: 128Warning 1196 Some non-transactional changed tables couldn't be rolled back 129ROLLBACK TO has_comment; 130Warnings: 131Warning 1196 Some non-transactional changed tables couldn't be rolled back 132USE replicate_do_db; 133INSERT INTO replicate_do_db.t2 VALUES("after rollback to"); 134Warnings: 135Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it accesses a non-transactional table after accessing a transactional table within the same transaction. 136INSERT INTO replicate_do_db.t1 VALUES(50); 137USE binlog_ignore_db; 138COMMIT; 139include/show_binlog_events.inc 140Log_name Pos Event_type Server_id End_log_pos Info 141master-bin.000001 # Query # # BEGIN 142master-bin.000001 # Query # # use `test`; INSERT INTO replicate_do_db.t1 VALUES(20) 143master-bin.000001 # Query # # SAVEPOINT `has_comment` 144master-bin.000001 # Query # # use `replicate_do_db`; INSERT INTO replicate_do_db.t1 VALUES(30) 145master-bin.000001 # Query # # use `replicate_do_db`; INSERT INTO replicate_do_db.t2 VALUES("in savepoint has_comment") 146master-bin.000001 # Query # # SAVEPOINT `mixed_cases` 147master-bin.000001 # Query # # use `replicate_do_db`; INSERT INTO replicate_do_db.t2 VALUES("in savepoint mixed_cases") 148master-bin.000001 # Query # # use `replicate_do_db`; INSERT INTO replicate_do_db.t1 VALUES(40) 149master-bin.000001 # Query # # ROLLBACK TO `mixed_cases` 150master-bin.000001 # Query # # ROLLBACK TO `has_comment` 151master-bin.000001 # Query # # use `replicate_do_db`; INSERT INTO replicate_do_db.t2 VALUES("after rollback to") 152master-bin.000001 # Query # # use `replicate_do_db`; INSERT INTO replicate_do_db.t1 VALUES(50) 153master-bin.000001 # Xid # # COMMIT /* XID */ 154include/sync_slave_sql_with_master.inc 155[on slave] 156# 157# Verify INSERT statements in savepoints are executed, for MyISAM table 158# is not effected by ROLLBACK TO 159SELECT * FROM replicate_do_db.t2 WHERE s LIKE '% savepoint %'; 160s 161in savepoint has_comment 162in savepoint mixed_cases 163# 164# Verify INSERT statements on the Innodb table are rolled back; 165SELECT * FROM replicate_do_db.t1 WHERE a IN (30, 40); 166a 167 168# BUG#55798 Slave SQL retry on transaction inserts extra data into 169# non-transaction table 170# ---------------------------------------------------------------- 171# To verify that SQL thread does not retry a transaction which can 172# not be rolled back safely, even though only a temporary error is 173# encountered. 174 175[connection master] 176USE replicate_do_db; 177DROP TABLE t1, t2; 178CREATE TABLE t1(c1 INT KEY, c2 CHAR(100)) ENGINE=InnoDB; 179CREATE TABLE t2(c1 INT) ENGINE=MyISAM; 180CREATE TABLE t3(c1 INT) ENGINE=InnoDB; 181INSERT INTO t1 VALUES(1, "master"); 182SET @@session.binlog_direct_non_transactional_updates= FALSE; 183include/sync_slave_sql_with_master.inc 184# [ on slave ] 185USE replicate_do_db; 186SET @timeout_old= @@GLOBAL.innodb_lock_wait_timeout; 187SET GLOBAL innodb_lock_wait_timeout= 1; 188STOP SLAVE SQL_THREAD; 189include/wait_for_slave_sql_to_stop.inc 190START SLAVE SQL_THREAD; 191include/wait_for_slave_sql_to_start.inc 192# Verify the SQL thread doesn't retry the transaction when one of 193# its statements has modified a non-transactional table. 194# ---------------------------------------------------------------- 195 196# INSERT statement inserts a row to a non-transactional table. 197# [ on slave ] 198BEGIN; 199# It will lock table t1 on the row in which c1 is 1 until COMMIT or ROLLBACK 200UPDATE t1 SET c2= "slave" WHERE c1= 1; 201# [ on master ] 202BEGIN; 203INSERT INTO t3 VALUES(1); 204INSERT INTO t2 VALUES(1); 205Warnings: 206Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it accesses a non-transactional table after accessing a transactional table within the same transaction. 207UPDATE t1 SET c2='INSERT INTO t2 VALUES(1)' WHERE c1= 1; 208COMMIT; 209# [ on slave ] 210include/wait_for_slave_sql_error.inc [errno=1205] 211ROLLBACK; 212START SLAVE SQL_THREAD; 213include/wait_for_slave_sql_to_start.inc 214 215# INSERT ... SELECT statement inserts a row to a non-transactional table. 216# [ on slave ] 217BEGIN; 218# It will lock table t1 on the row in which c1 is 1 until COMMIT or ROLLBACK 219UPDATE t1 SET c2= "slave" WHERE c1= 1; 220# [ on master ] 221BEGIN; 222INSERT INTO t3 VALUES(1); 223INSERT INTO t2 SELECT 2; 224Warnings: 225Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it accesses a non-transactional table after accessing a transactional table within the same transaction. 226UPDATE t1 SET c2='INSERT INTO t2 SELECT 2' WHERE c1= 1; 227COMMIT; 228# [ on slave ] 229include/wait_for_slave_sql_error.inc [errno=1205] 230ROLLBACK; 231START SLAVE SQL_THREAD; 232include/wait_for_slave_sql_to_start.inc 233 234# UPDATE statement updates a row to a non-transactional table. 235# [ on slave ] 236BEGIN; 237# It will lock table t1 on the row in which c1 is 1 until COMMIT or ROLLBACK 238UPDATE t1 SET c2= "slave" WHERE c1= 1; 239# [ on master ] 240BEGIN; 241INSERT INTO t3 VALUES(1); 242UPDATE t2 SET c1= 3; 243Warnings: 244Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it accesses a non-transactional table after accessing a transactional table within the same transaction. 245UPDATE t1 SET c2='UPDATE t2 SET c1= 3' WHERE c1= 1; 246COMMIT; 247# [ on slave ] 248include/wait_for_slave_sql_error.inc [errno=1205] 249ROLLBACK; 250START SLAVE SQL_THREAD; 251include/wait_for_slave_sql_to_start.inc 252 253# MULTI-UPDATE statement updates a row to a non-transactional table. 254# [ on slave ] 255BEGIN; 256# It will lock table t1 on the row in which c1 is 1 until COMMIT or ROLLBACK 257UPDATE t1 SET c2= "slave" WHERE c1= 1; 258# [ on master ] 259BEGIN; 260INSERT INTO t3 VALUES(1); 261UPDATE t2, t3 SET t2.c1=4, t3.c1= 4; 262Warnings: 263Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement accesses nontransactional table as well as transactional or temporary table, and writes to any of them. 264UPDATE t1 SET c2='UPDATE t2, t3 SET t2.c1=4, t3.c1= 4' WHERE c1= 1; 265COMMIT; 266# [ on slave ] 267include/wait_for_slave_sql_error.inc [errno=1205] 268ROLLBACK; 269START SLAVE SQL_THREAD; 270include/wait_for_slave_sql_to_start.inc 271 272# DELETE statement deletes a row from a non-transactional table. 273# [ on slave ] 274BEGIN; 275# It will lock table t1 on the row in which c1 is 1 until COMMIT or ROLLBACK 276UPDATE t1 SET c2= "slave" WHERE c1= 1; 277# [ on master ] 278BEGIN; 279INSERT INTO t3 VALUES(1); 280DELETE FROM t2; 281Warnings: 282Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it accesses a non-transactional table after accessing a transactional table within the same transaction. 283UPDATE t1 SET c2='DELETE FROM t2' WHERE c1= 1; 284COMMIT; 285# [ on slave ] 286include/wait_for_slave_sql_error.inc [errno=1205] 287ROLLBACK; 288START SLAVE SQL_THREAD; 289include/wait_for_slave_sql_to_start.inc 290 291# CREATE TEMPORARY TABLE statement in the transaction 292# [ on slave ] 293BEGIN; 294# It will lock table t1 on the row in which c1 is 1 until COMMIT or ROLLBACK 295UPDATE t1 SET c2= "slave" WHERE c1= 1; 296# [ on master ] 297BEGIN; 298INSERT INTO t3 VALUES(1); 299CREATE TEMPORARY TABLE IF NOT EXISTS temp_t(c1 INT); 300UPDATE t1 SET c2='CREATE TEMPORARY TABLE IF NOT EXISTS temp_t(c1 INT)' WHERE c1= 1; 301COMMIT; 302# [ on slave ] 303include/wait_for_slave_sql_error.inc [errno=1205] 304ROLLBACK; 305START SLAVE SQL_THREAD; 306include/wait_for_slave_sql_to_start.inc 307 308# DROP TEMPORARY TABLE statement in the transaction 309# [ on slave ] 310BEGIN; 311# It will lock table t1 on the row in which c1 is 1 until COMMIT or ROLLBACK 312UPDATE t1 SET c2= "slave" WHERE c1= 1; 313# [ on master ] 314BEGIN; 315INSERT INTO t3 VALUES(1); 316DROP TEMPORARY TABLE IF EXISTS temp_t; 317UPDATE t1 SET c2='DROP TEMPORARY TABLE IF EXISTS temp_t' WHERE c1= 1; 318COMMIT; 319# [ on slave ] 320include/wait_for_slave_sql_error.inc [errno=1205] 321ROLLBACK; 322START SLAVE SQL_THREAD; 323include/wait_for_slave_sql_to_start.inc 324 325# Verify that the SQL thread doesn't retry the transaction if one 326# of the sub-statements has modified a non-transactional table. 327# ---------------------------------------------------------------- 328CREATE FUNCTION f_insert() 329RETURNS INT 330BEGIN 331INSERT INTO t2 VALUES(1); 332RETURN 2; 333END| 334CREATE FUNCTION f_insert_select() 335RETURNS INT 336BEGIN 337INSERT INTO t2 SELECT 2; 338RETURN 2; 339END| 340CREATE FUNCTION f_update() 341RETURNS INT 342BEGIN 343UPDATE t2 SET c1=3; 344RETURN 2; 345END | 346CREATE TABLE t4 (c1 INT) | 347INSERT INTO t4 VAlUES(1),(2) | 348CREATE FUNCTION f_multi_update() 349RETURNS INT 350BEGIN 351UPDATE t2, t4 SET t2.c1=4, t4.c1= 4; 352RETURN 2; 353END | 354CREATE FUNCTION f_delete() 355RETURNS INT 356BEGIN 357DELETE FROM t2; 358RETURN 2; 359END | 360 361# The INSERT statement in a function inserts a row into a 362# non-transactional table. 363# [ on slave ] 364BEGIN; 365# It will lock table t1 on the row in which c1 is 1 until COMMIT or ROLLBACK 366UPDATE t1 SET c2= "slave" WHERE c1= 1; 367# [ on master ] 368BEGIN; 369INSERT INTO t3 VALUES(1); 370INSERT INTO t3 VALUES(f_insert()); 371Warnings: 372Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement accesses nontransactional table as well as transactional or temporary table, and writes to any of them. 373UPDATE t1 SET c2='INSERT INTO t3 VALUES(f_insert())' WHERE c1= 1; 374COMMIT; 375# [ on slave ] 376include/wait_for_slave_sql_error.inc [errno=1205] 377ROLLBACK; 378START SLAVE SQL_THREAD; 379include/wait_for_slave_sql_to_start.inc 380 381# The INSERT ... SELECT statement in a function inserts a row into a 382# non-transactional table. 383# [ on slave ] 384BEGIN; 385# It will lock table t1 on the row in which c1 is 1 until COMMIT or ROLLBACK 386UPDATE t1 SET c2= "slave" WHERE c1= 1; 387# [ on master ] 388BEGIN; 389INSERT INTO t3 VALUES(1); 390INSERT INTO t3 VALUES(f_insert()); 391Warnings: 392Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement accesses nontransactional table as well as transactional or temporary table, and writes to any of them. 393UPDATE t1 SET c2='INSERT INTO t3 VALUES(f_insert())' WHERE c1= 1; 394COMMIT; 395# [ on slave ] 396include/wait_for_slave_sql_error.inc [errno=1205] 397ROLLBACK; 398START SLAVE SQL_THREAD; 399include/wait_for_slave_sql_to_start.inc 400 401# The UPDATE statement in a function updates a row of a 402# non-transactional table. 403# [ on slave ] 404BEGIN; 405# It will lock table t1 on the row in which c1 is 1 until COMMIT or ROLLBACK 406UPDATE t1 SET c2= "slave" WHERE c1= 1; 407# [ on master ] 408BEGIN; 409INSERT INTO t3 VALUES(1); 410INSERT INTO t3 VALUES(f_update()); 411Warnings: 412Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement accesses nontransactional table as well as transactional or temporary table, and writes to any of them. 413UPDATE t1 SET c2='INSERT INTO t3 VALUES(f_update())' WHERE c1= 1; 414COMMIT; 415# [ on slave ] 416include/wait_for_slave_sql_error.inc [errno=1205] 417ROLLBACK; 418START SLAVE SQL_THREAD; 419include/wait_for_slave_sql_to_start.inc 420 421# The MULTI-UPDATE statement in a function updates a row of a 422# non-transactional table. 423# [ on slave ] 424BEGIN; 425# It will lock table t1 on the row in which c1 is 1 until COMMIT or ROLLBACK 426UPDATE t1 SET c2= "slave" WHERE c1= 1; 427# [ on master ] 428BEGIN; 429INSERT INTO t3 VALUES(1); 430INSERT INTO t3 VALUES(f_multi_update()); 431Warnings: 432Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement accesses nontransactional table as well as transactional or temporary table, and writes to any of them. 433UPDATE t1 SET c2='INSERT INTO t3 VALUES(f_multi_update())' WHERE c1= 1; 434COMMIT; 435# [ on slave ] 436include/wait_for_slave_sql_error.inc [errno=1205] 437ROLLBACK; 438START SLAVE SQL_THREAD; 439include/wait_for_slave_sql_to_start.inc 440 441# The DELETE statement in a function deletes a row from a 442# non-transactional table. 443# [ on slave ] 444BEGIN; 445# It will lock table t1 on the row in which c1 is 1 until COMMIT or ROLLBACK 446UPDATE t1 SET c2= "slave" WHERE c1= 1; 447# [ on master ] 448BEGIN; 449INSERT INTO t3 VALUES(1); 450INSERT INTO t3 VALUES(f_delete()); 451Warnings: 452Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement accesses nontransactional table as well as transactional or temporary table, and writes to any of them. 453UPDATE t1 SET c2='INSERT INTO t3 VALUES(f_delete())' WHERE c1= 1; 454COMMIT; 455# [ on slave ] 456include/wait_for_slave_sql_error.inc [errno=1205] 457ROLLBACK; 458START SLAVE SQL_THREAD; 459include/wait_for_slave_sql_to_start.inc 460SET @@global.innodb_lock_wait_timeout= @timeout_old; 461# 462# Clean up 463# 464DROP DATABASE replicate_do_db; 465DROP DATABASE binlog_ignore_db; 466include/rpl_end.inc 467