MySQL主存复制(8.0版本)

本文详细介绍了在MySQL 8.0版本中如何进行主从复制的配置,包括初始化环境、主库与从库的设置、用户权限配置、二进制日志的使用以及主从同步状态的检查和排错。测试结果显示主从复制功能成功建立。
摘要由CSDN通过智能技术生成

====================== 在两个完全一致的环境下===================

初始化环境。

同步时间

yum -y install ntp ntpdate
ntpdate cn.pool.ntp.org
hwclock --systohc

关闭防火墙

systemctl stop firewalld
systemctl disable firewalld

环境规划:

在主库上:

修改主库配置文件:开启log-bin功能,并指定server_id为1.这里log-bin必须指定,不然的话bin-log日志会根据主机名来命名,假如主库的主机名改变了,那主从复制就失效了。
添加

vim /etc/my.cnf
[mysqld]
server_id=27
log-bin=mysql-bin
log-bin-index=master-bin.index

重启服务:

[root@localhost ~]# systemctl stop mysql
[root@localhost ~]# systemctl start mysql

创建一个用于让从数据库连接的用户

mysql> create user 'copy'@'%' identified with mysql_native_password by 'Admin@123';
mysql> grant replication slave on *.* to 'copy'@'%';

刷新授权表信息

mysql> flush privileges;

获取主节点当前binary log文件名和位置(position)

mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 |      155 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
在从库上:

修改配置文件,必须指定中继日志的名称

[mysqld]
server_id=66
relay-log=relay-log
relay-log-index=relay-log.index

重启服务:

[root@localhost ~]# systemctl stop mysql
[root@localhost ~]# systemctl start mysql

在从(Slave)节点上设置主节点参数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值