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 build Master and Slave in MYSQL

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

Share

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

This article mainly explains "how to build a master and slave in MYSQL". Friends who are interested may wish to take a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "how to build a master and follower in MYSQL"!

1. Create three new virtual machines on the virtual machine, namely vm4 192.168.56.4 (master), vm2 192.168.56.88 (slave), vm3 192.168.56.100 (slave), and the systems are all redhat 6.5. The database version is vm4:mysql 5.7.12, vm2: mysql 5.7.12, vm3:mysql5.6.23

2. Binlog is also enabled from the slave library, and the log_slave_updates parameter is not configured (because it will become the master library)

3. After following the regular steps, show slave status\ G on the slave library and see that the status of the Slave_IO_Running process is Connecting.

The error is Last_IO_Error: error connecting to master 'root@192.168.56.4:3306'-retry-time: 30 retries: 1

You can't see anything from here, so check the error log.

The error log is as follows

2017-06-22 10:50:27 2063 [ERROR] Slave I Error_code O: error connecting to master 'root@192.168.56.4:3306'-retry-time: 30 retries: 1, Error_code: 2003

2017-06-22 10:50:27 2063 [Warning] Slave SQL: If a crash happens this configuration does not guarantee that the relay log info will be consistent, Error_code: 0

2017-06-22 10:50:27 2063 [Note] Slave SQL thread initialized, starting replication inlog 'binlog.000007' at position 450, relay log'. / vm3-relay-bin.000001' position: 4

It turns out that slave has no face, master.

In the slave library using mysql-h 192.168.56.4-P 3306-uroot-p test, it is found that it is indeed not connected to master

4, Baidu error number Error_code: 2003

The Internet says that there are the following possibilities

1), the network is not working

2), the password is incorrect

3), pos is wrong

4), the firewall is not turned off

I can ping test, password is also correct, pos is also correct.

5. My problem is that I didn't turn off the firewall. Test again after turning off the firewall.

The error is found as follows:

[root@vm4] # mysql-h 192.168.56.100-uroot-p

Enter password:

ERROR 1130 (HY000): Host '192.168.56.4' is not allowed to connect to this MySQL server

The reason is that the account does not allow remote login.

6. Modify permissions so that the account can be logged in remotely (each node is modified)

Mysql > select host,user from mysql.user

+-+ +

| | host | user |

+-+ +

| | 192.168.56.100 | repl | |

| | 192.168.56.100 | root | |

| | 192.168.56.88 | repl | |

| | 192.168.56.88 | root | |

| | localhost | mysql.sys |

| | localhost | root |

+-+ +

6 rows in set (0.00 sec)

Mysql > grant all privileges on *. * to 'root'@'%' identified by' root' with grant option

Query OK, 0 rows affected, 1 warning (0.01 sec)

Mysql > select host,user from mysql.user

+-+ +

| | host | user |

+-+ +

| |% | root |

| | 192.168.56.100 | repl | |

| | 192.168.56.100 | root | |

| | 192.168.56.88 | repl | |

| | 192.168.56.88 | root | |

| | localhost | mysql.sys |

| | localhost | root |

+-+ +

7 rows in set (0.00 sec)

7, test again, slave_io and slave_sql are both yes status, no problem. Build successfully

At this point, I believe you have a deeper understanding of "how to build the master and slave of MYSQL". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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