如何使用replicate-rewrite-db实现复制映射和Replicate_Wild_Do_Table实现复制过滤
Node1和Node2是两台不同业务的MySQL服务器。
业务方有需求将node1上的employees库的departments和dept_manager表同步到node2上的hellodb库。
node1的employee有如下6个表:
employees > show table;
+------ ---------------+
| Tables_in_employees |
+------------- -----+
|部门|
|部门经理 |
|部门员工 |
|员工|
|工资
仅节点2需要将其部门和 dept_manager 表复制到 hellodb 库。
经过实验,详细步骤如下:
1.导出node1中的数据并传输到node2:
mysqldump -uroot -pAbcd@1234 -q --single-transaction员工部门dept_manager --master-data=2 >Employees.sql # 注意导出时不要加-B
scpEmployees.sqlnode2:/root/
2.然后去node2导入刚才的数据
mysql -uroot -pAbcd@1234 hellodb
source /root/employees.sql
显示表格;
+--------------------+
| Tables_in_hellodb |
+ ------------------+
|部门|
|部门经理 |
|学生 |
|教师 |
+--------------------+
一组 4 行(0.00 秒)
< p>可以看到已经导入了2个表。head -35 /root/employees.sql,记下change master的位置,例如
-- CHANGE MASTER TO MASTER_LOG_FILE='mysql.000021', MASTER_LOG_POS=234757251;
3.停止node2并更改配置文件
/etc/int.d/mysql stop
修改node2配置文件。添加以下 3 行:
replicate-rewrite-db=employees -> hellodb
replicate-wild-do-table=hellodb.departments
< p>replicate-wild-do-table=hellodb.dept_manager/etc/int.d/mysql start
4、配置主从关系
将 MASTER 更改为
MASTER_HOST='192.168.2.171',
MASTER_USER='rpl',
MASTER_PASSWORD='Abcd@1234',
MASTER_LOG_FILE='mysql.000021',
MASTER_LOG_POS=234757251;
显示从属状态 \G
[(none)] > 显示从属状态\G
******************************** * ** 1.行****************************
Slave_IO_State:
Master_Host :192.168.2.171
Master_user:RPL
Master_port:3306
Connect_retry:60
& & Master_Log_文件:mysql.000021
Read_Master_Log_Pos:234757251
Relay_Log_File:t72-relay-bin.000001
Relay_Log_Pos:4
Relay_Master_Log_File: mysql.000021
Slave_IO_Running:否
Slave_SQL_Running:否
Replicate_Do_DB:
复制e_Ignore_DB:
Replicate_do_table :
Replicate_ignore_table:
Replicate_wild_do_table:HelloDB.Departments Will_ignore_table:
Last_Errno:0
Last_Error:
Skip_Counter:0
Exec_Master_Log_Pos:234757251
Relay_Log_Space:154
Until_Condition :无
Until_Log_File:
Until_Log_Pos:0
Master_SSL_Allowed:否
Master_SSL_CA_File:
Master_SSL_CA_Path:< /p>
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:NULL
Master_SSL_Verify_Server_Cert:否
Last_IO_Errno:0
Last_IO_Error:
< p> Last_SQL_Errno:0Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:0
Master_UUID:
p>Master_Info_File:/data/mysql/master.info
SQL_Dlay:0
Sql_remaining_Dlay:NULL
SLAVE_SQL_Running_STATE:
_Crl:
Master_SSL_Crlpath:
Retrieved_GTID_SET:
Executed_GTID_SET:
Auto_position:0
REPLICATE_REWRITE_DB:(员工, HelloDB)
Channel_name :
Master_TLS_Version:
集合中的 1 行(0.00 秒)
启动从属;
显示从机状态 \G
[(无)] > 显示从机状态\G
************* ************** 1.行 ********** ******************
< p> ' ' ' s ' s ' s ' s ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 使用使用 ' ' 使用使用 ' 使用使用使用使用使用使用使用 ' 整个出来出出出出'''s'是'''s'是''''''后'通过out'''''通过'通过------------------------ P> Master_user: RPLMaster_port: 3306
Connect_retry: 60
Master_log_file :MySQL.000021
Read_Master_LOG_POS:234757251
Relay_Log_File:t72-relay-bin.000002
Relay_Log_Pos:316
Relay_Master_Log_File:mysql .000021
Slave_IO_Running:是
Slave_SQL_Running:是
Replicate_Do_DB:
Replicate_Do_Table:
< p> Replicate_Ignore_Table:< /p>Replicate_Wild_Do_Table: hellodb.departments,hellodb.dept_manager
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
>SKIP_COUNTER:0
Exec_master_log_pos:234757251
Relay_log_space:521
Until_condition:无
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: 否
Master_SSL_CA_File:
< p> Master_SSL_CA_Path:Master_ssl_cert:
Master_SSL_CIPHER:
Master_SSL_KEY:
Seconds_behind_master:0
Master_SSL_server_cert:否 P Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:71
Master_UUID:02d27620-1d8c-11e7-b0 28 -000c295b7c01
Master_Info_File: /data/mysql/master.info
Sql_dlay: 0
Sql_remaining_Dlay: NULL
SLAVE_SQL_Running_State: 从属有读取所有中继日志;等待 F 或更多更新 p>
Master_Retry_Count: 86400
Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: 主_SSL_CrL:
Master_SSL_CRLPATH:
检索的_GTID_SET: P>
Executed_Set:
Auto_position:0
Replicate_rewrite_db:(员工,hellodb)
Channel_Name:
Master_TLS_Version:< /p>
一组 1 行(0.00 秒)
5.测试
在node1上测试。
以上是如何使用replicate-rewrite-db实现复制映射和Replicate_Wild_Do_Table实现复制过滤。小编相信有些知识点在我们日常工作中可能会看到或者用到。到达的。希望您能从本文中了解更多信息。更多详情请关注行业资讯频道。
2. 本站积分货币获取途径以及用途的解读,想在本站混的好,请务必认真阅读!
3. 本站强烈打击盗版/破解等有损他人权益和违法作为,请各位会员支持正版!
4. 编程技术 > 如何使用replicate-rewrite-db实现复制映射和Replicate_Wild_Do_Table实现复制过滤