MySQL不同庫名相同表結構實現主從配置

haoge0205發表於2015-10-10
資料庫版本 5.6.16

在兩個伺服器上,存在不同名字的資料庫,但是兩個資料庫中的所有表結構相同,實現主從複製。

主庫伺服器的資料庫名為yoon,從庫伺服器的庫名為hank

在從庫的my.cnf配置檔案中新增如下引數,並重啟資料庫
replicate-rewrite-db = yoon -> hank

設定主從:
change master to master_host='172.16.9.243',master_port=3306,master_user='master',master_password='123456',master_log_file='mysql-bin.000036',master_log_pos=107;

在主庫插入資料
mysql> insert into yoon values (1,'a');
Query OK, 1 row affected (0.00 sec)


mysql> select * from yoon;
+------+------+
| id   | name |
+------+------+
|    1 | a    |
+------+------+
1 row in set (0.00 sec)


在從庫檢視:
mysql> use hank
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A


Database changed
mysql> select * from yoon;
+------+------+
| id   | name |
+------+------+
|    1 | a    |
+------+------+
1 row in set (0.00 sec)


OK,沒問題。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28939273/viewspace-1813718/,如需轉載,請註明出處,否則將追究法律責任。

相關文章