Use RDS and local mysql to do master-slave synchronization to achieve multi-server data synchronization

Introduction: Recently, there is a project to do multi-server data synchronization. The solution I designed is to use RDS as the master database, and mysql on each server as the slave database to synchronize the data on RDS. Read and write separation, all data writing is written to RDS, and data reading is read from local mysql, so that the data read on each server can be guaranteed to be consistent through synchronization.
Recently, there is a project to do multi-server data synchronization. The solution I designed is to use RDS as the master database, and mysql on each server as the slave database to synchronize the data on RDS. Read and write separation, all data writing is written to RDS, and data reading is read from local mysql, so that the data read on each server can be guaranteed to be consistent through synchronization. The specific configuration steps are as follows:

1. Enter the local server, first close the mysql database

service mysql stop

2. Modify the configuration information in /ect/my.cnf

server-id = 10001 #Keep the id unique

#GTID:

gtid_mode=on

enforce_gtid_consistency=on

#binlog

log_bin= /alidata/log/mysql/slave-binlog.log

log-slave-updates=1

binlog_format=mixed

#relay log

skip_slave_start=1

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

expire_logs_days = 10

max_binlog_size = 100M

replicate-do-db = test #Database to be synchronized

replicate-ignore-db = mysql #Do not need to synchronize the database

replicate-ignore-db = information_schema #Do not need to synchronize the database

replicate-ignore-db = performance_schema #Do not need to synchronize the database

slave-skip-errors = 1032 #Because there was a 1032 error during synchronization, the synchronization was terminated, so I skipped this error

3、重启本地mysql数据库

service mysql start

4、链接RDS数据库,将RDS中的数据库导入到本地数据库中,

(1)、先锁RDS表,禁止写入操作

flush tables with read lock;

(2)、从RDS导出:mysqldump -uroot -ptest -hmasterhost.mysql.rds.aliyuncs.com> /tmp/test.sql

(3)、再导入到本地: mysql -uroot -p test < /tmp/test.sql ,记得需要先建库test

5、进入本地数据库设定主库信息

mysql>change master to master_host = 'masterhost.mysql.rds.aliyuncs.com', master_port = 3306, master_user = 'catest', master_password='masterpassword', master_auto_position = 1;

6、start slave

7、show slave status \G

查看系统返回信息中 Slave_IO_Running 和 Slave_SQL_Running 的状态是否为 Yes,如下所示。

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

两个都是yes 表示成功

8、 所有的服务器配置完毕后,将RDS上的表解锁

unlock tables;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324844516&siteId=291194637