Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to synchronize mysql databases with different CVM

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The following is about how to synchronize mysql databases on different cloud servers. If you are interested, let's take a look at this article. I believe it will be of some help to you after reading how to synchronize mysql databases on different cloud servers.

Goal:

The self-built database on CVM An is synchronized with the database built on CVM B.

Aliyun's RDS database An is synchronized to the self-built database on CVM B.

The database name of An is: mytest

Basics: linux, my.cnf will be configured

Start:

The former An is called the master CVM and the latter B is the slave CVM.

First check on CVM A: sql statement: show master status

Get the value of File,Position.

'mysql-bin.000039',' 1538, (this will be used later)

On B CVM, modify: / etc/my.cnf.

Stop mysql before modifying it.

Add the following sentences:

Server-id = 2

Expire_logs_days = 10

Max_binlog_size = 100m

Replicate-do-db = mytest

Replicate-ignore-db = mysql

Replicate-ignore-db = information_schema

Replicate-ignore-db = preformance_schema

Slave-skip-errors=all

# GTID

Gtid_mode=on

Enforce_gtid_consistency=on

Binlog_format=row

Log-slave-updates=1

After modification, restart mysql.

3.B CVM, enter mysql

Mysql > show slave status\ G

View the status of slave CVM.

If so, stop.

Mysql > stop slave

Then write this sentence:

Mysql > change master to master_host='*',master_port=3306,master_user='*',master_password='*',master_log_file='mysql-bin.000039', master_log_pos=1538

Master_log_file='mysql-bin.000039' and master_log_pos=1538; are found on CVM An above.

When executing this sentence, an error may be reported because the previous slave has not been cleared.

Mysql > reset slave all

That's it.

Restart

Mysql > start slave

Check again

Mysql > show slave status\ G

With these three sentences, that's right!

Slave_IO_State: Waiting for master to send event

Slave_IO_Running:Yes

Slave_SQL_Runing:Yes

After that, the updates of the mytest database in CVM A will be synchronized to CVM B.

For example, create a new table, and after the B CVM is refreshed, you can also see the new table.

3. Add that if CVM B only needs to synchronize part of the data table.

You can modify the my.cnf of B CVM and add

Replicate-do-table=db_name1.table_name1

Replicate-do-table=db_name1.table_name2

Replicate-do-table=db_name2.table_name1

Read the above details on how to synchronize mysql databases on different cloud servers and see if you have gained anything. If you want to know more about it, you can continue to follow our industry information section.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report