Mysql read-write separate construction (2) personalized configuration


Through the introduction in the previous chapter, we have been able to achieve full table synchronization of databases with the same name in different instances. Today, through the introduction of this chapter, we synchronize the specified tables of the same name database and synchronize the specified tables of different name databases.

1. Synchronize the specified table in the database with the same name

1.1 Modify the configuration file

Custom synchronization only needs to modify the client configuration file.
Insert picture description here

[mysqld]
#以下为主从读写配置 
server-id=2
#备份数据库  如果是多个数据库 就配置第二行 如test、test1
#binlog-do-db=test
#通过配置此节点 配置同步的表为test库的table_name_1 
#如果需要配置第二张就再增加一行即可  如 
#replicate-do-table=test.table_name_1
#replicate-do-table=test.table_name_2
replicate-do-table=test.table_name_1
log-bin=mysql-bin

1.2 Restart the client mysql service

#停止mysql服务
net stop mysql
#启动mysql服务  
net start mysql  

Here, we have completed the synchronization of the custom table of the database with the same name under different instances.

2. Synchronize the specified tables in different database names

2.1 Use a picture to illustrate what we are going to do

Custom synchronization only needs to modify the client configuration file.
This is a bit abstract, so let's make an explanation according to our example.
The database name on the server server is test, and the database name on the client server is myuser. We require that the table_name_1 in the test library be synchronized to myuser.
Insert picture description here

2.2 Modify the configuration file

# Through replicate-rewrite-db node can map two databases with different names
replicate-rewrite-db = test-> myuser
# replicate-do-table node is to write the database name of the client <
-please pay attention to replicate-do- here table = myuser.table_name_1
Insert picture description here

[mysqld]
#以下为主从读写配置 
server-id=2
#备份数据库  如果是多个数据库 就配置第二行 如test、test1
#binlog-do-db=test
replicate-do-table=myuser.table_name_1
log-bin=mysql-bin
replicate-rewrite-db = test-> myuser

2.3 Restart the client mysql service

#停止mysql服务
net stop mysql
#启动mysql服务  
net start mysql  

Execution here, we have completed the synchronization of the custom table with different name database under different instances.

Published 17 original articles · praised 0 · visits 467

Guess you like

Origin blog.csdn.net/weixin_36008116/article/details/104813758