mysql replication 修改庫名
–replicate-rewrite-db=from_name->to_name
Command-Line Format –replicate-rewrite-db=old_name->new_name
Option-File Format replicate-rewrite-db
Permitted Values
Type string
Tells the slave to translate the default database (that is, the one selected by USE) to to_name if it was from_name on the master. Only statements involving tables are affected (not statements such as CREATE DATABASE, DROP DATABASE, and ALTER DATABASE), and only if from_name is the default database on the master. This does not work for cross-database updates. To specify multiple rewrites, use this option multiple times. The server uses the first one with a from_name value that matches. The database name translation is done before the –replicate-* rules are tested.
If you use this option on the command line and the “>” character is special to your command interpreter, quote the option value. For example:
shell> mysqld –replicate-rewrite-db="olddb->newdb"
適用情況:
比如,master與slave同步test這個庫,但因為需要slave需要將test改名為testbak,master不能改,就需要這個參數
在my.cnf中加入
binlog-do-db=test
replicate-rewrite-db=test->testbak
重啟mysql,在master的test庫修改東西,看slave的hackers庫是否已經修改。查看show slave status是否正常。
總結一下:slave修改庫名,master不變的情況下
題外話:在遇到slave query 同步錯誤時,可以使用如下方法解決:
slave stop;
set global sql_slave_skip_counter=1;
slave start;
不過有可能會丟失數據。先看清楚是因為什麼導致的錯誤。