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 realize Master-Slave and Master-Master Mode in mysql

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

Share

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

How to realize master-slave mode and master-master mode in mysql? in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Implementation Mechanism of mysql replication

1) first, the main mysql saves the operation statement in bin-log

2) start a process or thread from the server to initiate a request to the master mysql

3) copy the operation statements in the bin-log of the master mysql from the relay-log of the mysql from mysql

4) execute these operation statements on the slave

Configuration

Master mysql here mainly introduces the content to be changed (master and slave are changed from their respective independent modes)

1) add or modify the following in / etc/my.cnf

Bin-log = mysql.bin-log # defines the file name of the bin-log (saved in the data directory by default)

Bin-log-index = mysql.bin-log.index # defines the file name of the bin-log-index

Binlog-format = mixed # defines the format of binlog

Server-id = 1 # make sure that the server-id of the master mysql is less than the server-id of the slave mysql

2) start mysql and configuration

# service mysqld start

# mysql # enter mysql

# set password for ('mima')

# set password for ('mima')

# grant replication slave,replication client on *. * to identified by 'mima'; # gives username permission to copy

# flush privileges

# show master status; # View the status of the primary mysql

From mysql

1) add or modify the following in / etc/my.cnf

Relay-log = mysql.relay-log # defines the file name of the relay-log (saved in the data directory by default)

Relay-log-index = mysql.relay-log.index # defines the file name of the relay-log-index

Server-id = 11 # must be greater than the server-id of the main mysql

2) start mysql and configuration

# service mysqld start

# mysql # enter mysql

# set password for ('mima')

# set password for ('mima')

# flush privileges

# change master to master_host='master_ip',master_user='username',master_password='mima'

# Link main mysql

# start slave

# show slave status

test

Create an OR table on the master mysql to see if the slave is automatically 'replicated'.

As a matter of fact, the master-master mode is that both sides are master and subordinate to each other, which can be simply understood as integrating the master-slave configuration files.

Master mode has one of the biggest problems is that when both master and slave write data to the same table at the same time, if the corresponding id is automatically increased, this is a serious problem. In order to solve this problem, it is necessary to set different starting values at the low end and specify an automatically increasing variable of 2.

This is the answer to the question about how to achieve master-slave and master-master mode in mysql. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

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