当前位置: 首页 > news >正文

简述mysql 主从复制原理及其工作过程,配置一主两从并验证

第一种基于binlog的主从同步

首先对主库进行配置:

[root@openEuler-1 ~]# vim /etc/my.cnf

启动服务

[root@openEuler-1 ~]# systemctl enable --now mysqld

主库的配置

从库的配置

第一个从库

[root@openEuler-1 ~]# vim /etc/my.cnf


[root@openEuler-1 ~]# systemctl enable --now mysqld

mysql> change master to
    -> master_host='192.168.1.13',
    -> master_user='rep',
    -> master_password='123456',
    -> master_log_file='binlog.000001',
    -> master_log_pos=678;
Query OK, 0 rows affected, 8 warnings (0.02 sec)

mysql> start slave;
Query OK, 0 rows affected, 1 warning (0.05 sec)

mysql> show slave status \G
*************************** 1. row ***************************
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes

第二个从库

[root@openEuler-1 ~]# vim /etc/my.cnf


[root@openEuler-1 ~]# systemctl enable --now mysqld

mysql> change master to
    -> master_host='192.168.1.13',
    -> master_user='rep',
    -> master_password='123456',
    -> master_log_file='binlog.000001',
    -> master_log_pos=678;
Query OK, 0 rows affected, 8 warnings (0.02 sec)

mysql> start slave;
Query OK, 0 rows affected, 1 warning (0.05 sec)

mysql> show slave status \G
*************************** 1. row ***************************
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes

进行测试

在主库中

mysql> create database test;
mysql> use test;
mysql> create table td1(id int(10),name varchar(20));
mysql> insert into td1 values (1,'张三'),(2,'李遂');
从库中

第二种基于gtid的主从同步配置

在主库和从库中分别开启gtid

[root@openEuler-1 ~]# vim /etc/my.cnf


[root@openEuler-1 ~]# systemctl restart mysqld.service

从库1:mysql> stop slave;
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> change master to
    -> master_host='192.168.1.13',
    -> master_user='rep',
    -> master_password='123456',
    -> master_auto_position=1;
Query OK, 0 rows affected, 7 warnings (0.02 sec)

mysql> start slave;
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> show slave status \G
*************************** 1. row ***************************
            Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
            
 

从库2:

mysql> stop slave;
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> change replication source to
    -> source_host='192.168.1.13',
    -> source_user='rep',
    -> source_password='123456',
    -> source_auto_position=1;
Query OK, 0 rows affected, 2 warnings (0.02 sec)

mysql> start replica;
Query OK, 0 rows affected (0.02 sec)

mysql> show slave status \G
*************************** 1. row ***************************
            Slave_IO_Running: Yes
            Slave_SQL_Running: Yes

测试:

主库:

mysql> create database py;
Query OK, 1 row affected (0.01 sec)

mysql> use py;
Database changed
mysql> create table yp(id int(10), name varchar(20));
Query OK, 0 rows affected, 1 warning (0.02 sec)

mysql> insert into yp values (1,'张三');
Query OK, 1 row affected (0.01 sec)

从库中

http://www.lryc.cn/news/524050.html

相关文章:

  • oracle之行转列
  • Windows电脑安装USB Redirector并实现内外网跨网USB共享通信访问
  • kafka学习笔记4-TLS加密 —— 筑梦之路
  • grafana + Prometheus + node_exporter搭建监控大屏
  • 深度学习在语音识别中的应用
  • RabbitMQ 高级特性
  • 第01章 07 MySQL+VTK C++示例代码,实现医学影像数据的IO数据库存储
  • Mysql创建定时任务
  • 【MySQL篇】使用mysqldump导入报错Unknown collation: ‘utf8mb4_0900_ai_ci‘的问题解决
  • 专业学习|最优化理论(目标函数、约束条件以及解题三板斧)
  • 【Linux】gawk编辑器二
  • Hadoop美食推荐系统 爬虫1.8w+数据 协同过滤余弦函数推荐美食 Springboot Vue Element-UI前后端分离
  • 吴恩达深度学习——神经网络编程的基础知识
  • 第14个项目:E-Learning在线学习平台Python源码
  • Qt之文件系统操作和读写
  • 【物联网】keil仿真环境设置 keilV5可以适用ARM7
  • VIVADO ILA IP进阶使用之任意设置ILA的采样频率
  • 网络编程-网络原理HTTP初识
  • 基于若依框架的动态分页逻辑的实现分析
  • 51c~ONNX~合集1
  • 【数据结构篇】顺序表 超详细
  • kubernetes 集群搭建(二进制方式)
  • linux平台RTMP|RTSP播放器如何回调SEI数据?
  • Vue uni-app免手动import
  • 7. 计算机视觉
  • 在服务器进行docker部署频繁提示permission denied
  • c/c++ static
  • C#中System.Text.Json:从入门到精通的实用指南
  • 内存故障原因与诊断(Reasons and Diagnosis of Memory Failure)
  • [操作系统] 进程状态详解