数据库版本 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,没问题。
转载于:https://www.cnblogs.com/hankyoon/p/5169697.html