mysql replication修改库名_MySQL

WBOY
发布: 2016-06-01 13:45:58
原创
1169 人浏览过

bitsCN.com

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;
不过有可能会丢失数据。先看清楚是因为什么导致的错误。

bitsCN.com
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板