mysql replication小记

有必要新开一个mysql replication分类。在看replication options时。看到一个参数:


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






重启mysql,在master的hacker库修改东西,看slave的hackers库是否已经修改。查看show slave status是否正常。





题外话:在遇到slave query 同步错误时,可以使用如下方法解决:

slave stop;

set global sql_slave_skip_counter=1;

slave start;