传统的mysql复制就是主-从复制,它会有一个主,一个或多个从,在主节点提交与执行完事物之后,通过bin-log(2进制日志),将其(异步的)通过从节点上的IO线程发送到从节点上,并将bin-log日志存到从节点的readly-log(中继日志)中,通过sql线程以重新执行(在基于语句的复制中),或应用(在基于行的复制中),当从节点连上主节点后,会向主节点发送上次同步的位置,主节点将日志文件发给从节点 。
下载官方源
环境准备
酷以先卸载数据库的5.6的版本
[root@db01 ~]# yum remove -y mariadb-libs-5.5.64-1.el7.x86_64
创建目录并进入
[root@db02 ~]# mkdir /server/
[root@db02 ~]# cd /server
上传刚下载的5.7数据库
[root@db02 server]# rz
[root@db02 server]# ll
total 644552
-rw-r--r-- 1 root root 660017902 Jul 31 19:08 mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
解压并作链接
[root@db02 server]# tar xf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
[root@db02 server]# ln -s mysql-5.7.30-linux-glibc2.12-x86_64 /server/mysql
[root@db02 server]# ll
total 644552
lrwxrwxrwx 1 root root 35 Aug 1 11:47 mysql -> mysql-5.7.30-linux-glibc2.12-x86_64
drwxr-xr-x 9 root root 129 Aug 1 11:18 mysql-5.7.30-linux-glibc2.12-x86_64
-rw-r--r-- 1 root root 660017902 Jul 31 19:08 mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
创建用户,禁止交互且不建家目录
[root@db02 server]# useradd mysql -s /sbin/nologin -M
[root@db02 server]# id mysqluid=1000(mysql)gid=1000(mysql)groups=1000(mysql)
设置 环境变量并执行
[root@db02 server]# vim /etc/profile.d/mysql.sh
export PATH=/server/mysql/bin:$PATH
[root@db02 server]# source /etc/profile
查看版本
[root@db02 server]# mysql -V
mysql Ver 14.14 Distrib 5.7.30, for linux-glibc2.12 (x86_64) using EditLine wrapper
授权和创数据目录
[root@db02 server]# chown -R mysql.mysql /server/*
[root@db02 server]# mkdir /data/mysql/data -p
[root@db02 server]# chown -R mysql.mysql /data
安装依赖
[root@db02 server]# yum install -y libaio-devel
初始化
# 5.6 版本 初始化命令 /application/mysql/scripts/mysql_install_db
# 5.7跳过密码初始化
[root@db02 server]# mysqld --initialize-insecure --user=mysql --basedir=/server/mysql --datadir=/data/mysql/data
2020-08-01T03:52:14.741614Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-08-01T03:52:15.930825Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-08-01T03:52:16.083888Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-08-01T03:52:16.149231Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 63dc1ce2-d3aa-11ea-9f23-000c29e86875.
2020-08-01T03:52:16.150259Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-08-01T03:52:16.681964Z 0 [Warning] CA certificate ca.pem is self signed.
2020-08-01T03:52:17.154436Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
复制启动脚本
[root@db02 server]# cp /server/mysql/support-files/mysql.server /etc/init.d/mysqld
配置文件
[root@db02 server]# cat /etc/my.cnf
[mysqld]
user=mysql
basedir=/server/mysql
datadir=/data/mysql/data
server_id=2
port=3306
log_bin = mysql-bin
sync_binlog = 1
binlog_ignore_db = information_schema
binlog_ignore_db = performation_schema
binlog_ignore_db = sys
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
[mysql]
port = 3306
default-character-set = utf8mb4
[client]
port = 3306
default-character-set = utf8mb4
启动数据库
[root@db02 server]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/data/mysql/data/db02.err'.
SUCCESS!
登陆数据库
[root@db02 server]# mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.30-log MySQL Community Server (GPL)
Copyright (c) 2000, 2020, 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>