mysql 8.0 主从复制配置
背景:
主库:
192.168.211.128 从库:
192.168.211.129 一、关闭防火墙
[root@node01 ~]# systemctl disable firewalld
[root@node01 ~]# systemctl stop firewalld
[root@node01 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1) 二、关闭selinux
[root@node01 ~]# vi /etc/selinux/config
SELINUX=disabled
[root@node01 ~]# getenforce
Disabled 临时关闭selinux
[root@node01 ~]# setenforce 0
setenforce: SELinux is disabled 三、卸载centos自带数据库
[root@node01 ~]# rpm -qa | grep mariadb | xargs -i yum remove -y {}
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.56-2.el7 will be erased
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Running transaction check
---> Package postfix.x86_64 2:2.10.1-6.el7 will be erased
--> Finished Dependency Resolution Dependencies Resolved =======================================================================================
Package Arch Version Repository Size
=======================================================================================
Removing:
mariadb-libs x86_64 1:5.5.56-2.el7 @anaconda 4.4 M
Removing for dependencies:
postfix x86_64 2:2.10.1-6.el7 @anaconda 12 M Transaction Summary
=======================================================================================
Remove 1 Package (+1 Dependent package) Installed size: 17 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : 2:postfix-2.10.1-6.el7.x86_64 1/2
Erasing : 1:mariadb-libs-5.5.56-2.el7.x86_64 2/2
Verifying : 1:mariadb-libs-5.5.56-2.el7.x86_64 1/2
Verifying : 2:postfix-2.10.1-6.el7.x86_64 2/2 Removed:
mariadb-libs.x86_64 1:5.5.56-2.el7 Dependency Removed:
postfix.x86_64 2:2.10.1-6.el7 Complete!
[root@node01 ~]# rpm -qa | grep mariadb
[root@node01 ~]# 四、添加用户组及用户
[root@node01 ~]# groupadd mysql
[root@node01 ~]# useradd -g mysql mysql
[root@node01 ~]# id mysql
uid=1000(mysql) gid=1000(mysql) groups=1000(mysql)
[root@node01 ~]# passwd mysql
Changing password for user mysql.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@node01 ~]# 五、创建mysql相关目录
[root@node01 ~]# mkdir -p /data/mysql3306/data
[root@node01 ~]# mkdir -p /data/mysql3306/binlog
[root@node01 ~]# chown -R mysql.mysql /data* 六、下载mysql8.0安装包,上传并解压 下载地址:
https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.18-linux-glibc2.12-x86_64.tar 解压mysql安装包:
[mysql@node01 ~]$ tar -xvf mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz 七、创建mysql安装包软连接
[root@node01 data]# ln -s /data/mysql-8.0.18-linux-glibc2.12-x86_64 /usr/local/mysql
[root@node01 data]# chown -R mysql.mysql /usr/local/mysql* 八、创建my.cnf参数文件
[root@node01 data]# vi /etc/my.cnf
[client]
port=3306
socket=/tmp/mysql.sock [mysqld]
port=3306
user=mysql
server_id=1
socket=/tmp/mysql.sock
basedir=/usr/local/mysql
datadir=/data/mysql3306/data
log-error=/data/mysql3306/data/error.log
log_bin=/data/mysql3306/binlog/mysql-bin 九、配置用户环境变量
[mysql@node01 ~]$ vi .bash_profile
# .bash_profile # Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi # User specific environment and startup programs PATH=$PATH:$HOME/.local/bin:$HOME/bin export PATH
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin [root@node02 ~]# vi /etc/profile
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin 十、初始化mysql数据库
[mysql@node01 ~]$ mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql3306/data 十一、添加mysql服务
[root@node01 data]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld 十二、启动mysql数据库、登录数据库
[mysql@node01 ~]$ /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!
[mysql@node01 ~]$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.18 MySQL Community Server - GPL Copyright (c) 2000, 2019, 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 |
+--------------------+
4 rows in set (0.00 sec) mysql> 十三、配置mysql数据库自动启动
[root@node01 data]# chkconfig --add mysqld
[root@node01 data]# chkconfig --list Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'. mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
十四、从库配置跟主库一致,只是参数文件不一样
[root@node02 ~]# cat /etc/my.cnf
[client]
port=3306
socket=/tmp/mysql.sock [mysqld]
port=3306
user=mysql
server_id=2
socket=/tmp/mysql.sock
basedir=/usr/local/mysql
datadir=/data/mysql3306/data
log-error=/data/mysql3306/data/error.log
log_bin=/data/mysql3306/binlog/mysql-bin 十五、主库创建用户repl@%并授权
mysql> create user 'repl'@'192.168.211.%' identified by 'mysql';
Query OK, 0 rows affected (0.31 sec) mysql> grant replication slave on *.* to 'repl'@'192.168.211.%';
Query OK, 0 rows affected (0.05 sec) mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec) 十六、关闭主从数据库
[root@node01 data]# /etc/init.d/mysqld stop
Shutting down MySQL... SUCCESS! [root@node02 ~]# /etc/init.d/mysqld stop
Shutting down MySQL. SUCCESS! 十七、修改主从库参数文件
主库:
[client]
port=3306
socket=/tmp/mysql.sock [mysqld]
port=3306
user=mysql
server_id=1
socket=/tmp/mysql.sock
basedir=/usr/local/mysql
datadir=/data/mysql3306/data
log-error=/data/mysql3306/data/error.log
log_bin=/data/mysql3306/binlog/mysql-bin
gtid_mode=ON
enforce_gtid_consistency=ON
log_slave_updates=1 从库:
[client]
port=3306
socket=/tmp/mysql.sock [mysqld]
port=3306
user=mysql
server_id=2
socket=/tmp/mysql.sock
basedir=/usr/local/mysql
datadir=/data/mysql3306/data
log-error=/data/mysql3306/data/error.log
log_bin=/data/mysql3306/binlog/mysql-bin
gtid_mode=ON
enforce_gtid_consistency=ON
log_slave_updates=1 十八、开启数据库
[root@node01 data]# /etc/init.d/mysqld start
Starting MySQL... SUCCESS! [root@node02 ~]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS! 十九、从库开启主从复制
mysql> CHANGE MASTER TO
-> MASTER_HOST='192.168.211.128',
-> MASTER_USER='repl',
-> MASTER_PASSWORD='mysql',
-> MASTER_PORT=3306,
-> MASTER_AUTO_POSITION=1;
Query OK, 0 rows affected, 2 warnings (0.02 sec) mysql> start slave;
Query OK, 0 rows affected (0.01 sec) mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.211.128
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 155
Relay_Log_File: node02-relay-bin.000002
Relay_Log_Pos: 369
Relay_Master_Log_File: mysql-bin.000001
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: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 155
Relay_Log_Space: 578
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: d282ef12-ff38-11ea-bcf5-000c291cc010
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
Master_public_key_path:
Get_master_public_key: 0
Network_Namespace:
1 row in set (0.00 sec) ERROR:
No query specified mysql>
mysql 8.0 主从复制配置的更多相关文章
- MySQL 8.0.15 配置 MGR单主多从
转载自:http://www.cnblogs.com/zhangzihong/p/10443526.html 一.简介 MySQL Group Replication(简称MGR)字面意思是mysql ...
- mysql 8.0 主从复制的优化
mysql 8.0复制改进一简介: 基于GTID下的并行复制,本文不考虑MGR架构二 主要特性 1 基于writeset的下的改进型并行复制 我在之前的一篇文章关于并行复制中详细的介绍了关 ...
- Mysql安装及主从复制配置
1.下载 mysql数据库 wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.9-linux-glibc2.5-x86_64.ta ...
- mysql 5.5主从复制配置
首先将主库现有的要实现主从的数据库原原本本地复制到从库上,目的是一开始就让主从同步,让binlog日志从最新的记录开始同步! 备份: 方法1:快捷导出所要的库如(库goods)[注意:该方法仅适合My ...
- linux MySql 在 Master 主从复制配置
在 Master 服务器上建立用于 Slave 服务器复制数据的帐户 [root@master ~]# mysql mysql> grant replication slave,replicat ...
- MySQL 8.0安装 + 配置环境变量 + 连接 cmd
MySQL 安装教程 搜索 MySQL,进入官网,找到 download 点击适用于 window community 版本,点击图中第二个 450.7 M 的安装包进行下载 这里有五个选项,选择第二 ...
- 通过 Docker 部署 Mysql 8.0 主从模式
文章转载自:http://www.mydlq.club/article/106/ 系统环境: Mysql 版本:8.0.23 Docker 版本:19.03.13 一.为什么需要 Mysql 主从复制 ...
- MySQL 8.0安装以及初始化错误解决方法
MySQL 8.0 安装配置及错误排查 官网下载 CentOS7环境下的具体安装步骤 初始化MySQL发生错误的解决方法 忘记数据库root密码 官网下载 mysql官网下载链接:https://de ...
- 二:mysql安装配置、主从复制配置详解
作者:NiceCui 本文谢绝转载,如需转载需征得作者本人同意,谢谢. 本文链接:http://www.cnblogs.com/NiceCui/p/8213723.html 邮箱:moyi@moyib ...
随机推荐
- 3、Spring Boot日志
1.日志框架 市面上的日志框架:JUL.JCL.Jboss-logging.logback.log4j.log4j2.slf4j.... 日志门面 (日志的抽象层) 日志实现 JCL(Jakarta ...
- hackrf GPS欺骗
在对GPS欺骗之前,先对GPS的知识做一个简单的介绍 GPS 系统本身非常复杂, 涉及到卫星通信等各个领域. 这里只是简单介绍一下. 我们通常所说的 GPS 全球定位系统是由美国国防部建造完成. 目前 ...
- bWAPP----OS Command Injection
OS Command Injection 界面: 给一个域名,它帮你返回DNS 代码: 1 <div id="main"> 2 3 <h1>OS Comma ...
- [head first 设计模式]第二章 观察者模式
[head first 设计模式]第二章 观察者模式 假如我们有一个开发需求--建造一个气象观测站展示系统.需求方给我们提供了一个WeatherObject对象,能够自动获得最新的测量数据.而我们要建 ...
- [python学习手册-笔记]003.数值类型
003.数值类型 ❝ 本系列文章是我个人学习<python学习手册(第五版)>的学习笔记,其中大部分内容为该书的总结和个人理解,小部分内容为相关知识点的扩展. 非商业用途转载请注明作者和出 ...
- 如何解决vue2.0 打包之后 打开index.html出现空白页
如何解决vue2.0 打包之后 打开index.html出现空白页 1.打包之前修改三个文件 1.1.第一步,找到build文件,在webpack.prod.conf.js 第25行左右 ...
- 从使用传统Web框架到切换到Spring Boot后的总结
1.前言 其实我接触 Spring Boot 的时间并不长,所以还算一个初学者,这篇文章也算是我对 Spring Boot 学习以及使用过程中的复盘,如果文章出现描述错误或表达不清晰的地方,欢迎大家在 ...
- Mybatis log plugin 破解!!!
前言 今天重新装了IDEA2020,顺带重装了一些插件,毕竟这些插件都是习惯一直在用,其中一款就是Mybatis Log plugin,按照往常的思路,在IDEA插件市场搜索安装,艹,眼睛一瞟,竟然收 ...
- Go语言基础--1.1 变量的声明
1.标准格式: var name type (var 关键字 name 变量名 type 类型) 命名规则:建议使用驼峰命名法 例如:var userName string var ...
- PyQt(Python+Qt)学习随笔:QTabWidget选项卡部件操作控制类属性movable和tabsClosable介绍
老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 QTabWidget的操作控制类属性包括movable.tabsClosable这两个. 1. mo ...