当前位置:网站首页>MySQL master-slave replication configuration construction, one step in place
MySQL master-slave replication configuration construction, one step in place
2022-07-30 07:50:00 【Leo, Fei】
1.准备工作
from already installedlinuxThe virtual machine is cloned to prepare for the slave library

Then power on the cloned virtual machine 登录
vim /etc/sysconfig/network-scripts/ifcfg-ens33TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
IPADDR="192.168.220.128" # 设置的静态IP地址
NETMASK="255.255.255.0" # 子网掩码
GATEWAY="192.168.220.2" # 网关地址
DNS1="192.168.220.2" # DNS服务器
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=afd0baa3-8bf4-4e26-8d20-5bc426b75fd6
DEVICE=ens33
ONBOOT=yes
ZONE=public如果你的系统没有vim 下载一个就好,不然用vi 一样的效果
vi /etc/sysconfig/network-scripts/ifcfg-ens33


The static resources inside are configured according to their actual situation
特别注意ipIf the address is to be modified, it must be at the beginningip中间 我这里就是128~254之间
好了言归正传
从库的IP地址在128~254Just write one in there
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
IPADDR="192.168.220.130" # 设置的静态IP地址
NETMASK="255.255.255.0" # 子网掩码
GATEWAY="192.168.220.2" # 网关地址
DNS1="192.168.220.2" # DNS服务器
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=afd0baa3-8bf4-4e26-8d20-5bc426b75fd6
DEVICE=ens33
ONBOOT=yes
ZONE=public我这里就写130了
Here from the libraryIP配置好了以后ESC 退出 -->: wq 保存退出
重启网络服务
ip地址修改完毕之后,需要重启网络服务,执行如下指令:
systemctl restart networkAfter restarting the networkIP已经发生了改变,此时重启虚拟机

重启后登录,输入ip addr This completes the server setup of the slave library

Then do the following preparations on the two servers
1.Fire please open3306端口号
firewall-cmd --zone=public --add-port=3306/tcp --permanent立即加载
firewall-cmd --reload查看端口号
firewall-cmd --zone=public --list-ports
成功,Open other ports in the same way
2.Start the two databases on the two servers
systemctl start mysqldThen log on to both serversMySQL验证是否可以正常启动
主库配置
1.退出数据库
输入
vim /etc/my.cnf在[mysqld]
最下面配置
log-bin=mysql-bin #[必须]启用二进制日志
server-id=200 #[必须]服务器唯一ID(唯一即可)

2.重启Mysql服务
systemctl restart mysqld
3.登录MySql 并执行如下指令,创建用户并授权
GRANT REPLICATION SLAVE ON *.* to 'xiaozhang'@'%' identified by '[email protected]';注:上面SQL的作用是创建一个用户 xiaozhang ,密码为 [email protected] ,并且给xiaozhang用户授予REPLICATION SLAVE权限.常用于建立复制时所需要用到的用户权限,也就是slave必须被master授权具有该权限的用户,才能通过该用户复制.
4.登录MySql数据库,查看master同步状态
show master status;

记录下File 和Position的值
Then don't operate
从库配置
1). 修改Mysql数据库的配置文件vim /etc/my.cnf

Because the slave library is cloned from the server of the master library All itself has oneserver-uuid是相同的,要修改一下,不然最后会报错,slave_IO_Running:no
The following is correct

输入
vim /var/lib/mysql/auto.cnf
to such a content interface,Just change the number at the back,Make master library and slave libraryserver-uuidInconsistencies can be avoided in advance
Don't delete too much If you delete it, you will not be able to log inMySql了
2. 重启Mysql服务
systemctl restart mysqld3. 登录Mysql数据库,设置主库地址及同步位置
change master to master_host='192.168.220.128',master_user='xiaozhang',master_password='[email protected]',master_log_file='mysql-bin.000001',master_log_pos=154;
注意: 这里的IPConfigure it according to the server address of your own main library,followed by the username and password,According to the configuration you just set,
Second, pay special attentionfile和positionConfigure according to the value just now,The special note here is here"0"的个数,Xiaobian suffered a loss

Go ahead by ten
这里配置3If such an error occurs after the step,表示当前有slave在运行

输入
start slave;
Close the previous one
4. 查看从数据库的状态
show slave status;
Entering this will display the data in rows,Do not let the change view(can be copied toNotepad++中查看)
Direct input is recommended
show slave status\G
表示将查询结果进行按列打印

双yes就可以了
测试
到Navicat中连接


在主库中创建一个数据库,Refresh the database of the slave library later,See if the slave library creates a database with the same name at the same time,The synchronization appears to indicate success,Create the table later,It's easy to test additions, deletions, and changes!
I heard that all the people who like it are paid monthly5w了,Object found,儿女双全了!!!
边栏推荐
- 预测人们对你的第一印象,“AI颜狗”的诞生
- Ali two sides: List several tips for Api interface optimization
- Proftpd配置文件
- MySQL什么时候用表锁,什么时候用行锁?
- Redis下载与安装
- 使用 Grafana 的 Redis Data Source 插件监控 Redis
- Selenium01
- Pioneer in Distributed Systems - Leslie Lambert
- Distance calculation from space vertex to straight line and its source code
- MySQL主从复制配置搭建,一步到位
猜你喜欢

VR机器人教你如何正确打乒乓球

STL源码剖析:bound friend template friend代码测试和理解

What new materials are used in the large aircraft C919?

PXE efficient mass network capacity

STL源码剖析:class template explicit specialization代码测试和理解

The Society of Mind - Marvin Minsky

Advanced multi-threading (lock strategy, spin+CAS, Synchronized, JUC, semaphore)

“AI教练”请进家,家庭智能健身蓬勃发展

Boot process and service control

限塑令下的新材料——聚乳酸(PLA)
随机推荐
Upload file -- file type, picture type, document type, video type, compressed package type
Required request body is missing 问题解决
DHCP原理与配置
空间直线到平面上的交点的计算证明及其源码
Headline 2: there are several kinds of common SQL errors in MySQL usage?
PXE efficient mass network capacity
The CTO said I was not advised to use SELECT *, why is that?
schur completement
C#的访问修饰符,声明修饰符,关键字有哪些?扫盲篇
舒尔补(schur completement)
限塑令下的新材料——聚乳酸(PLA)
Test Development Engineer Growth Diary 003 - Interface Automation Framework Construction
debian 问题
Network Protocol 03 - Routing and NAT
Multithreading basics (multithreaded memory, security, communication, thread pools and blocking queues)
“AI教练”请进家,家庭智能健身蓬勃发展
SE_01
What happens when @Bean and @Component are used on the same class?
B站崩了,如果是你是那晚负责的开发人员你会怎么做?
《心智社会》—马文·明斯基