mysql5.7.26做主从复制配置
一、首先两台服务器安装好mysql数据库环境
https://www.cnblogs.com/sky-cheng/p/10564604.html
二、主库master上创建主从复制账号
mysql> grant replication slave,replication client on *.* to 'repl'@'%' identified by 'Zaq1xsw@';
Query OK, rows affected, warning (0.00 sec)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
mysql> select user,host from user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| repl | % |
| root | % |
| mysql.session | localhost |
| mysql.sys | localhost |
+---------------+-----------+
rows in set (0.00 sec)
三、Master、Slave上分别设置不同的Server_id,主库上开启二进制日志
mysql> show variables like '%server_id%';
+----------------+-------+
| Variable_name | Value |
+----------------+-------+
| server_id | |
| server_id_bits | |
+----------------+-------+
如果配置文件没有设置server_id参数,则默认都是0
编辑/etc/my.cnf
添加service_id,它的值可以跟服务器的IP最后一位数字一样,这样就能保证内网中的服务器ID不重复。master上
server_id=
log-bin=master
binlog_format=row
slave上
server_id=
四、将主库做一次全量备份,并恢复到从库上
在主库上操作
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
rows in set (0.00 sec)
主库有一个test数据库
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| test |
+----------------+
row in set (0.00 sec)
有一个test表
mysql> select * from test;
+------+------+
| id | name |
+------+------+
| | aaaa |
+------+------+
row in set (0.00 sec)
表里有一条数据,开始备份主库
[root@node2 data]# mysqldump -uroot -p --all-databases > /home/mysql-5.7./bak/bak.sql
[root@node2 data]# scp -P25601 /home/mysql-5.7.26/bak/bak.sql root@172.28.18.69:/home/mysql-5.7.26/bak/ 在从库上操作,恢复主库数据
[root@localhost log]# mysql -uroot -p < /home/mysql-5.7./bak/bak.sql
Enter password:
[root@localhost log]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.7. MySQL Community Server (GPL) Copyright (c) , , Oracle and/or its affiliates. All rights reserved. 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. mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
rows in set (0.00 sec) mysql>
此时,从库里test数据库有了,里面也有test数据表里记录
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
rows in set (0.00 sec) mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
mysql> select * from test
-> ;
+------+------+
| id | name |
+------+------+
| | aaaa |
+------+------+
row in set (0.01 sec)
五、在slave上change msater 操作配置主从复制
首先获取主库日志文件名称和偏移量
mysql> show master status \G;
*************************** . row ***************************
File: master.
Position:
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set:
row in set (0.00 sec) ERROR:
No query specified mysql>
在从库上执行
mysql> change master to
-> master_host='172.28.18.103',
-> master_port=,
-> master_user='repl',
-> master_password='Zaq1xsw@',
-> master_log_file='master.000001',
-> master_log_pos=;
Query OK, rows affected, warnings (0.21 sec)
启动从库
mysql> start slave;
Query OK, rows affected (0.01 sec)
查看从库状态
mysql> show slave status\G;
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.28.18.103
Master_User: repl
Master_Port:
Connect_Retry:
Master_Log_File: master.
Read_Master_Log_Pos:
Relay_Log_File: localhost-relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File: master.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_UUID: ddbee8c3-76da-11e9--90b11c15be09
Master_Info_File: /home/mysql-5.7./data/master.info
此时:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
主从复制配置已经生效
六、测试数据
在主库插入一条数据
mysql> insert test values(,'bbbb');
Query OK, row affected (0.03 sec)
从库上查询
mysql> select * from test;
+------+------+
| id | name |
+------+------+
| | aaaa |
| | bbbb |
+------+------+
rows in set (0.00 sec)
数据已经复制成功了。
mysql5.7.26做主从复制配置的更多相关文章
- mysql5.7.26做主主配置
一.首先两台服务器安装好mysql数据库环境 参照linux rpm方式安装mysql5.1 https://www.cnblogs.com/sky-cheng/p/10564604.html 二.在 ...
- MySQL5.7.26二进制安装
1.安装系统版本 2.解压更换路径 tar xf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz mv mysql-5.7.26-linux-glibc2.12- ...
- mysql5.7.26 基于GTID的主从复制环境搭建
简单工作原理: (1)从库执行 change master to 语句,会立即将主库信息记录到master.info中 (2)从库执行 start slave语句,会立即生成IO_T和SQL_T (3 ...
- mysql5.7在windows下面的主从复制配置
目标:自动同步Master 服务器上面的Demo数据库到Slave 服务器的Demo数据库中. 对于一些操作系统比较强而使用频率又不高的东西,往往好久不去弄就忘记了,所以要经常记录起来,方便日后查阅. ...
- MySQL5.6基于GTID的主从复制配置
全局事务标示符(Global Transactions Identifier)是MySQL 5.6复制的一个新特性. GTID实际上是由UUID+TID组成的.其中UUID是一个MySQL实例的唯一标 ...
- centos 7 Mysql5.7 主从复制配置
1.环境 Centos 7 Mysql 5.7 Master 192.168.1.71 Slave01 192.168.1.72 2.分别配置master,slave01 # vi /etc/my. ...
- Centos7.5部署MySQL5.7基于GTID主从复制+并行复制+半同步复制+读写分离(ProxySQL) 环境- 运维笔记 (完整版)
之前已经详细介绍了Mysql基于GTID主从复制的概念,原理和配置,下面整体记录下MySQL5.7基于GTID主从复制+并行复制+增强半同步复制+读写分离环境的实现过程,以便加深对mysql新特性GT ...
- 关于Mysql5.6半同步主从复制的开启方法【转】
介绍 先了解一下mysql的主从复制是什么回事,我们都知道,mysql主从复制是基于binlog的复制方式,而mysql默认的主从复制方式,其实是异步复制. 主库实际上并不关心从库是否把数据拉完没有, ...
- 利用JDBC连接Eclipse和mySQL5.1.26数据库
初学JDBC,看了看书,自己动手的时候还是有很多地方有问题,最终终于解决了实现了数据库的连接.现将整个步骤描述如下: 环境:mySQL5.1.26(win 32bit), Eclipse JavaEE ...
随机推荐
- 使用KFold进行训练集和验证集的拆分,使用准确率和召回率来挑选合适的阈值(threshold) 1.KFold(进行交叉验证) 2.np.logical_and(两bool数组都是正即为正) 3.np.logical_not(bool数组为正即为反,为反即为正)
---恢复内容开始--- 1. k_fold = KFold(n_split, shuffle) 构造KFold的索引切割器 k_fold.split(indices) 对索引进行切割. 参数说明:n ...
- vue问题三:element ui的upload组件上传图片成功和移除事件
element ui的upload组件上传图片成功和移除事件: 登录后获取到后台传的token存到中: sessionStorage.setItem("token",data.ob ...
- Could not parse configuration: /hibernate.cfg.xml
hibernate需要联网验证dtd,错误原因:未联网或网速不行
- Tomcat指定JDK
那么当有多个JDK时,是否可以为Tomcat这类应用程序指定对应的JDK版本 如下图,只需修改catalina.sh 即可,不需要修改“tomcat/bin/setclasspath.sh” . “t ...
- 使用 tcpdump 抓包分析 TCP 三次握手、四次挥手与 TCP 状态转移
目录 文章目录 目录 前文列表 TCP 协议 图示三次握手与四次挥手 抓包结果 抓包分析 TCP 三次握手 数据传输 四次挥手 TCP 端口状态转移 状态转移 前文列表 <常用 tcpdump ...
- 利用Python进行异常值分析实例代码
利用Python进行异常值分析实例代码 异常值是指样本中的个别值,也称为离群点,其数值明显偏离其余的观测值.常用检测方法3σ原则和箱型图.其中,3σ原则只适用服从正态分布的数据.在3σ原则下,异常值被 ...
- Python实现打印螺旋矩阵功能的方法
Python实现打印螺旋矩阵功能的方法 本文实例讲述了Python实现打印螺旋矩阵功能的方法.分享给大家供大家参考,具体如下: 一.问题描述 输入N, 打印 N*N 螺旋矩阵 比如 N = 3,打印: ...
- java:Session(概述,三层架构实例(实现接口封装JDBC),Session实现简单购物车实例)
1.Session概述: Session:在计算机中,尤其是在网络应用中,称为“会话控制”.Session 对象存储特定用户会话所需的属性及配置信息.这样,当用户在应用程序的 Web 页之间跳转时,存 ...
- .on()之selector——jQuery
API:[https://www.jquery123.com/on/]
- this引用逸出
1.定义 public class UnsafeClass { public UnsafeClass(Button button) { button.addActionListener(new Act ...