include/master-slave.inc
[connection master]
#
# MDEV-15530 Variable replicate_rewrite_db cannot be found
#            in "show global variables"
#
# Create DBs and verify that slave has to be stopped before setting sys var
connection slave;
select @@session.server_id;
@@session.server_id
2
create database replica_db1;
create database y;
create database test_replica;
SELECT @@GLOBAL.replicate_rewrite_db, 'primary_db1->replica_db1,x->y' as 'Replicate_Rewrite_DB from SHOW SLAVE STATUS';
@@GLOBAL.replicate_rewrite_db	Replicate_Rewrite_DB from SHOW SLAVE STATUS
primary_db1->replica_db1,x->y	primary_db1->replica_db1,x->y
# Create DBs and tables on primary
connection master;
create database primary_db1;
create database x;
use primary_db1;
create table my_table (t int);
insert into my_table values (2),(4);
use x;
create table my_table (t int);
insert into my_table values (654),(532);
include/save_master_gtid.inc
# Check replica
connection slave;
include/sync_with_master_gtid.inc
include/diff_tables.inc [master:primary_db1.my_table,slave:replica_db1.my_table]
include/diff_tables.inc [master:x.my_table,slave:y.my_table]
SELECT @@GLOBAL.replicate_rewrite_db;
@@GLOBAL.replicate_rewrite_db
primary_db1->replica_db1,x->y
show tables from replica_db1;
Tables_in_replica_db1
my_table
select * from replica_db1.my_table;
t
2
4
show tables from y;
Tables_in_y
my_table
select * from y.my_table;
t
654
532
# Set replica sys var replicate_rewrite_db
connection slave;
SET @@GLOBAL.replicate_rewrite_db="test_master->test_replica";
ERROR HY000: This operation cannot be performed as you have a running slave ''; run STOP SLAVE '' first
include/stop_slave.inc
SET @save_replicate_rewrite_db = @@GLOBAL.replicate_rewrite_db;
SELECT @@GLOBAL.replicate_rewrite_db;
@@GLOBAL.replicate_rewrite_db
primary_db1->replica_db1,x->y
SET @@GLOBAL.replicate_rewrite_db="test_master->test_replica";
SHOW DATABASES like 'test_replica';
Database (test_replica)
test_replica
include/start_slave.inc
SELECT @@GLOBAL.replicate_rewrite_db, 'test_master->test_replica' as 'Replicate_Rewrite_DB from SHOW SLAVE STATUS';
@@GLOBAL.replicate_rewrite_db	Replicate_Rewrite_DB from SHOW SLAVE STATUS
test_master->test_replica	test_master->test_replica
# Create DB and tables on primary
connection master;
create database test_master;
use test_master;
create table my_table (t int);
insert into my_table values (1),(3);
include/save_master_gtid.inc
# Ensure that the replica receives all of the primary's events without
# error
connection slave;
include/sync_with_master_gtid.inc
Last_SQL_Error = 
Last_SQL_Errno = 0
SELECT @@GLOBAL.replicate_rewrite_db;
@@GLOBAL.replicate_rewrite_db
test_master->test_replica
SHOW tables from test_replica;
Tables_in_test_replica
my_table
select * from test_replica.my_table;
t
1
3
include/diff_tables.inc [master:test_master.my_table,slave:test_replica.my_table]
# Update of values on primary for DB not set in replication_rewrite_db
include/stop_slave.inc
include/reset_slave.inc
connection master;
use x;
insert into my_table values (314);
select * from my_table;
t
654
532
314
include/save_master_gtid.inc
connection slave;
include/start_slave.inc
SELECT @@GLOBAL.replicate_rewrite_db;
@@GLOBAL.replicate_rewrite_db
test_master->test_replica
include/sync_with_master_gtid.inc
select * from y.my_table;
t
654
532
# Dynamic updates to the replication filter should be lost after server restart
connection slave;
SELECT @@GLOBAL.replicate_rewrite_db;
@@GLOBAL.replicate_rewrite_db
test_master->test_replica
connection master;
use x;
insert into my_table values (1000);
select * from my_table;
t
654
532
314
1000
include/save_master_gtid.inc
connection slave;
include/stop_slave.inc
include/reset_slave.inc
include/rpl_restart_server.inc [server_number=2]
CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_MYPORT, MASTER_USER='root', MASTER_SSL_VERIFY_SERVER_CERT=0;
connection slave;
include/start_slave.inc
SELECT @@GLOBAL.replicate_rewrite_db;
@@GLOBAL.replicate_rewrite_db
primary_db1->replica_db1,x->y
include/sync_with_master_gtid.inc
select * from y.my_table;
t
654
532
314
1000
# Cleanup
connection master;
drop database test_master;
drop database primary_db1;
drop database x;
include/save_master_gtid.inc
connection slave;
include/sync_with_master_gtid.inc
drop database test_replica;
drop database replica_db1;
drop database y;
include/stop_slave.inc
include/start_slave.inc
include/rpl_end.inc
