MySQL8.0.33搭建主从复制

复制原理

复制基于binlog实现

redo log是InnoDb存储引擎独有的。在存储引擎层面实现。
binlog是存储所有的数据,包括非InnoDB。在server层面实现。


3大线程
主库binlog dump线程
从库io线程
从库sql线程

主从规划

IP

主机名

主从

os用户名

os密码

db用户名

db密码

MySQL版本

server-id

192.168.6.101

node01

root

oracle

root

oracle

8.0.33

1001

192.168.6.102

node02

root

oracle

root

oracle

8.0.33

1002

192.168.6.103

node03

root

oracle

root

oracle

8.0.33

1003

编辑配置文件

1、编辑配置文件,server-id支持在线修改
主库node01
[mysqld]
server-id=1001

从库node02
[mysqld]
server-id=1002

从库node03
[mysqld]
server-id=1003


主库node01
8.0之后默认开启binlog,8.0之前需要在参数文件中设置log-bin=on
root@localhost [(none)]> show variables like 'log_bin';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin       | ON    |
+---------------+-------+
1 row in set (0.00 sec)

主库创建复制用户


2、主库创建复制用户
root@localhost [(none)]> select user,host from mysql.user;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)

创建用户'repl'@'192.168.6.%'
root@localhost [mysql]> create user 'repl'@'192.168.6.%' identified by 'oracle';
Query OK, 0 rows affected (0.01 sec)

给用户授权   
root@localhost [mysql]> grant replication slave on *.* to 'repl'@'192.168.6.%';
Query OK, 0 rows affected (0.00 sec)

在从库node02、node03分别进行登录测试复制用户
[root@node02 mysql]# mysql -h192.168.6.101 -urepl -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.1.0 Source distribution

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

repl@192.168.6.101 [(none)]> 

[root@node03 mysql]# mysql -h192.168.6.101 -urepl -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 8.1.0 Source distribution

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值