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 deploy mysql two-way master-slave replication Mmurm

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the relevant knowledge of "how to deploy mysql two-way master-slave replication MMUM". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Through mysql master: configure mysql bi-directional synchronization database HA

Mysql Master: server: XUEGOD63 IP:192.168.1.63

Mysql Master: server: XUEGOD64 IP:192.168.1.64

Master-configure XUEGOD63

It has two identities:

Identity 1: Lord of XUEGOD64. Identity 2: the follower of XUEGOD64.

Create a database that requires synchronization

Mysql > create database HA

Mysql > use HA

Mysql > create table T1 (id int,name varchar (20))

Edit my.cnf

Vim / etc/my.cnf

Server-id = 1

Log-bin=mysql-bin-master

Binlog-do-db=HA

Binlog-ignore-db=mysql # avoid synchronizing mysql user-related configuration

Restart mysql, authorize

Systemctl restart mysqld

(if you restart the jam, kill drops and starts again)

Log in to the main server

Mysql-uroot-p123456

Set up a connection account for the slave server on the master server and grant REPLICATION SLAVE permission.

Mysql > grant replication slave on *. * to slave@'192.168.1.64' identified by '123456'

If it does not meet the password requirements, modify it as follows (version 5.7)

Mysql > set global validate_password_policy=0; # define complexity

Mysql > set global validate_password_length=1; # defines a length of 8 by default

Turn off password strength audit and add validate-password=off in my.cnf

Grant replication slave on *. * to slave@'10.10.10.%' identified by '123456'

Mysql > flush privileges; # remember to refresh the authorization table

Export data to the slave server

Make sure that the synchronized database is consistent before backing up a complete data copy on master.

Mysqldump-uroot-p123456 HA > HA.sql # can export the database

Method: scp HA.sql 192.168.1.64:/root

From-configure XUEGOD64 two database servers with the same mysql version and consistent data

View version

Mysql > show variables like'% version%'

Import the database, be consistent with the master database server, log in to the slave server, create the database and import

Mysql-uroot-p123456

Mysql > create database HA

Mysql > use HA

Mysql > source / root/HA.sql

Configure the my.cnf file

Vim / etc/my.cnf

Server-id = 2

Log-bin=mysql-bin-slave

Binlog-do-db=HA

Binlog-ignore-db=mysql

Test whether it is normal to log in from the account?

[root@xuegod64] # mysql-uslave-p123456-h 192.168.1.63

Stop the slave library, specify the master library of the slave library, and open the slave library

.

[root@XUEGOD64] # mysql-uroot-p123456

Mysql > stop slave

Mysql > change master to master_host='192.168.1.63',master_user='slave',master_password='123456'

# specify which is the master of xuegod64

Mysql > start slave

Mysql > show slave status\ G

At this point, the master (xuegod63)-à slave (xuegod64) has been built.

Master-configure XUEGOD64 master xuegod64 to authorize slave xuegod63

Set up a connection account on the master server xuegod64 for the slave server xuegod63 and grant REPLICATION SLAVE permission.

Grant replication slave on *. * to slave@'192.168.1.63' identified by '123456'

From-configure XUEGOD63 to test whether it is normal to log in from the account?

[root@xuegod63~] # mysql-uslave-p123456-h 192.168.1.64 # can log in

Stop the slave library, specify the master library of the slave library, and open the slave library

.

Specify which is the master of xuegod63

[root@XUEGOD63] # mysql-uroot-p123456

Mysql > change master to master_host='192.168.1.64',master_user='slave',master_password='123456'

Mysql > start slave

Mysql > show slave status\ G

At this point, the master (xuegod64)-à slave (xuegod63) has been built.

Check:

View slave status on XUEGOD63

View slave status on XUEGOD64

Insert data test:

Insert data on XUEGOD63 and view it on XUEGOD64

Mysql > insert into T1 values (2Jing 'Tianqing')

Insert data on XUEGOD64 and view it on XUEGOD63

Mysql > insert into T1 values (3 'hackers')

This is the end of the introduction of "how to deploy mysql two-way master-slave copy Mmurm M". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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