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
|
#
# This test validates that when the rewrite rules are
# specified for mysqlbinlog, we can replay the logs
# according to those rules. For instance, on SBR the
# USE clause will be rewritten properly and on RBR,
# the Table_map_log_event is also rewritten properly.
#
# Moreover, this also tests that a database not affected
# by the rewritting is left untouched.
#
# To be included in the binlog_rewrite_order.test
#
# parameters:
# --let $rewrite_from_db=<from_db>
# --let $rewrite_to_db=<to_db>
# [--let $other=<neutral_name_db>]
# --source extra/binlog_tests/mysqlbinlog_rewrite_db.test
#
if (!$other)
{
--let $other=_other_
}
RESET MASTER;
--eval CREATE SCHEMA $rewrite_from_db
--eval USE $rewrite_from_db
FLUSH LOGS;
CREATE TABLE test (id int);
CREATE TABLE tload (c1 TEXT);
SET SESSION BINLOG_FORMAT='STATEMENT';
INSERT INTO test (id) VALUES (1);
SET SESSION BINLOG_FORMAT='ROW';
INSERT INTO test (id) VALUES (2);
SET SESSION BINLOG_FORMAT=STATEMENT;
LOAD DATA INFILE '../../std_data/words.dat' INTO TABLE tload;
SET SESSION SQL_LOG_BIN=0;
--eval CREATE DATABASE $other
--eval USE $other
SET SESSION SQL_LOG_BIN=1;
CREATE TABLE t1 (a INT);
SET SESSION BINLOG_FORMAT='STATEMENT';
INSERT INTO t1 VALUES (1);
SET SESSION BINLOG_FORMAT='ROW';
INSERT INTO t1 VALUES (2);
--let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1)
SET SQL_LOG_BIN=0;
FLUSH LOGS;
--copy_file $datadir/$binlog_file $datadir/backup_$binlog_file
--eval CREATE SCHEMA $rewrite_to_db
RESET MASTER;
--eval TRUNCATE $other.t1
#
# Assert that the changes are applied when we rewrite the
# database name and also filter only those changes that affect
# the database with the new name
#
--exec $MYSQL_BINLOG --database=$rewrite_to_db --rewrite-db="$rewrite_from_db->$rewrite_to_db" --force-if-open $datadir/backup_$binlog_file | $MYSQL --local-infile=1
--let $diff_tables=$rewrite_from_db.test,$rewrite_to_db.test
--source include/diff_tables.inc
--let $diff_tables=$rewrite_from_db.tload,$rewrite_to_db.tload
--source include/diff_tables.inc
--eval TRUNCATE $rewrite_to_db.test
--eval TRUNCATE $rewrite_to_db.tload
--eval TRUNCATE $other.t1
RESET MASTER;
#
# Assert that the no changes are applied when we rewrite the
# database name and also filter only changes to the database
# with the old name
#
--exec $MYSQL_BINLOG --database=$rewrite_from_db --rewrite-db="$rewrite_from_db->$rewrite_to_db" --force-if-open $datadir/backup_$binlog_file | $MYSQL --local-infile=1
--eval USE $rewrite_to_db
--let $assert_text= Zero records on $rewrite_to_db.test
--let $assert_cond= COUNT(*) = 0 FROM test
--source include/assert.inc
--let $assert_text= There is NO data in 'tload' table
--let $assert_cond= COUNT(*) = 0 FROM tload
--source include/assert.inc
--eval TRUNCATE $rewrite_to_db.test
--eval TRUNCATE $rewrite_to_db.tload
--eval TRUNCATE $other.t1
RESET MASTER;
#
# Assert that if the database name is not rewritten, then
# it is applied properly.
#
--eval DROP TABLE $rewrite_to_db.test
--eval DROP TABLE $rewrite_to_db.tload
--eval DROP TABLE $other.t1
--exec $MYSQL_BINLOG --rewrite-db="$rewrite_from_db->$rewrite_to_db" --force-if-open $datadir/backup_$binlog_file | $MYSQL --local-infile=1
--let $assert_cond= COUNT(*) = 2 FROM $other.t1
--let $assert_text= Verify that other database was not rewritten
--source include/assert.inc
SET SQL_LOG_BIN=1;
--eval SET BINLOG_FORMAT=$saved_binlog_format
--eval DROP SCHEMA $rewrite_to_db
--eval DROP SCHEMA $rewrite_from_db
--eval DROP SCHEMA $other
RESET MASTER;
--remove_file $datadir/backup_$binlog_file
|