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 configure Mutual Master and Slave in MySQL

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article is to share with you about how to configure each other as masters and followers in MySQL. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article.

MySQL-VIP:192.168.1.200

2 MySQL-master1:192.168.1.201

3 MySQL-master2:192.168.1.202

four

5 OS version: CentOS 5.4

6 MySQL version: 5.0.89

7 Keepalived version: 1.1.20

I. MySQL master-master configuration

1. Modify MySQL configuration file

If you want to enable the binlog log feature for both MySQL, add the log-bin=MySQL-bin option in the [MySQLd] section of the MySQL configuration file.

The server-ID of two MySQL cannot be the same. By default, the serverID of both MySQL is 1. You need to modify one of them to 2.

2. Set 192.168.1.201 as the primary server of 192.168.1.202

Create a new authorized user on 192.168.1.201

View source

< id="highlighter_12830_clipboard" title="copy to clipboard" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="16" height="16" codebase="" type="application/x-shockwave-flash">

Print?

01 MySQL > grant replication slave on *. * to identified by replication

02 Query OK, 0 rows affected (0.00 sec)

03

04 MySQL > show master status

05 +-+

06 | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |

07 +-+

08 | MySQL-bin.000003 | 374 |

09 +-+

10 1 row in set (0.00 sec)

11 set 192.168.1.201 as your primary server on 192.168.1.202

twelve

13 MySQL > change master to master_host=192.168.1.201,master_user=replication,master_password=replication,master_log_file=MySQL-bin.000003,master_log_pos=374

14 Query OK, 0 rows affected (0.05sec)

fifteen

16 MySQL > start slave

17 Query OK, 0 rows affected (0.00 sec)

eighteen

19 MySQL > show slave statusG

20 * 1. Row * *

21 Slave_IO_State: Waiting for master to send event

22 Master_Host: 192.168.1.201

23 Master_User: replication

24 Master_Port: 3306

25 Connect_Retry: 60

26 Master_Log_File: MySQL-bin.000003

27 Read_Master_Log_Pos: 374

28 Relay_Log_File: MySQL-master2-relay-bin.000002

29 Relay_Log_Pos: 235

30 Relay_Master_Log_File: MySQL-bin.000003

31 Slave_IO_Running: Yes

32 Slave_SQL_Running: Yes

33 Replicate_Do_DB:

34 Replicate_Ignore_DB:

35 Replicate_Do_Table:

36 Replicate_Ignore_Table:

37 Replicate_Wild_Do_Table:

38 Replicate_Wild_Ignore_Table:

39 Last_Errno: 0

40 Last_Error:

41 Skip_Counter: 0

42 Exec_Master_Log_Pos: 374

43 Relay_Log_Space: 235

44 Until_Condition: None

45 Until_Log_File:

46 Until_Log_Pos: 0

47 Master_SSL_Allowed: No

48 Master_SSL_CA_File:

49 Master_SSL_CA_Path:

50 Master_SSL_Cert:

51 Master_SSL_Cipher:

52 Master_SSL_Key:

53 Seconds_Behind_Master: 0

54 1 row in set (0.00 sec)

3. Set 192.168.1.202 as the primary server of 192.168.1.201

Create a new authorized user on 192.168.1.202

View source

< id="highlighter_331829_clipboard" title="copy to clipboard" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="16" height="16" codebase="" type="application/x-shockwave-flash">

Print?

01 MySQL > grant replication slave on *. * to identified by replication

02 Query OK, 0 rows affected (0.00 sec)

03

04 MySQL > show master status

05 +-+

06 | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |

07 +-+

08 | MySQL-bin.000003 | 374 |

09 +-+

10 1 row in set (0.00 sec)

On 192.168.1.201, set 192.168.1.202 as your primary server

View source

< id= "highlighter_574354_clipboard" title= "copy to clipboard" classid= "clsid:d27cdb6

The above is how to configure each other as masters and slaves in MySQL. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

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