一、环境

192.168.56.102 为主服务器

192.168.56.101 为从服务器

Mysql5.7.20 二进制安装包环境

1、 下载免编译安装包并进行安装

从官网下载 mysql-5.7.20-linux-glibc2.5-x86_64.tar.gz

官网:  http://dev.mysql.com/downloads/mysql/

wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
[root@mysql-slave ~]# mv mysql-5.7.20-linux-glibc2.12-x86_64 /usr/local/mysql
[root@mysql-slave ~]# cd /usr/local/mysql
[root@mysql-slave mysql]# mkdir –p data/mysql #存放数据目录
[root@mysql-slave mysql]# useradd mysql -s /sbin/nologin
[root@mysql-slave mysql]# chown -R mysql:mysql data/mysql/
[root@localhost mysql]# ./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/mysql –initialize
# 初始化并安装,会提示产生一个默认密码:root@localhost: Tb8lw2pmN&dH

支持加密
# ./bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data/mysql

#/usr/local/mysql/support-files/mysql.server start
启动看看,我这里没有成功,发现配置文件存在问题。
把配置文件复制到/etc/my.cnf # cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
# vim /etc/my.cnf
[root@localhost bin]# cat /etc/my.cnf  #照如下修改配置文件

[mysqld]

basedir=/usr/local/mysql

datadir=/usr/local/mysql/data/mysql

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

# Settings user and group are ignored when systemd is used.

# If you need to run mysqld under a different user or group,

# customize your systemd unit file for mariadb according to the

# instructions in http://fedoraproject.org/wiki/Systemd

character_set_server=utf8

init_connect='SET NAMES utf8'

[mysqld_safe]

log-error=

pid-file=/var/run/mariadb/mariadb.pid

#

# include all files from the config directory

#

!includedir /etc/my.cnf.d

[client]

default-character-set=utf8  

然后设置链接,启动服务

[root@localhost bin]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost bin]# chmod 755 /etc/init.d/mysqld
[root@localhost mysql]# systemctl start mysqld

连接mysql

[root@localhost mysql]# mysql -uroot –p
-bash: mysql: command not found
[root@localhost mysql]# cd bin
[root@localhost bin]# ./mysql
[root@localhost bin]# ./mysql -uroot -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.7.20

Copyright (c) 2000, 2017, 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;

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

mysql> alter user 'root'@'localhost' identified by '1';

Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

查看日志文件

[root@mysql-m mysql]# cat mysql-m.err

2、    复制配置

2.1 在主服务器上的/etc/my.cnf上开启log-bin:

在[mysqld]下添加
server-id=1
log-bin=/usr/local/mysql/data/mysql/mysql-bin
[root@mysql-m mysql]# systemctl restart mysqld

2.2 建立复制帐户

mysql> grant replication slave on *.* to 'rep'@'192.168.56.%' identified by '1';
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
锁表:
mysql> flush table with read lock;
查看主库状态:
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 | 599 | | | |

新开一个窗口,备份主库

[root@mysql-m ~]# /usr/local/mysql/bin/mysqldump -uroot -p'1' --events -A -B | gzip > /server/backup/mysql_bak.$(data+%F).sql.gz
-bash: data+%F: command not found
mysqldump: [Warning] Using a password on the command line interface can be insecure.
解锁:
mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)

3、从库配置

[root@mysql-s mysql]# vim /etc/my.cnf  #如果有开启bin-log建议关闭。
server-id=2
重启mysql服务
[root@mysql-s mysql]# systemctl restart mysqld
检查从库log-bin
mysql> show variables like 'log_bin';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin | OFF |
+---------------+-------+
1 row in set (0.01 sec)
把备份文件复制到从库并解压
[root@mysql-s ~]# cd /server/backup/
[root@mysql-s backup]# gzip -d mysql_bak.sql.gz
[root@mysql-s backup]# ll
total 764
-rw-r--r-- 1 root root 780324 Nov 5 14:59 mysql_bak.sql
还原备份文件到从库
[root@mysql-s backup]# cd /usr/local/mysql
[root@mysql-s mysql]# bin/mysql -uroot -p'1' < /server/backup/mysql_bak.sql
mysql: [Warning] Using a password on the command line interface can be insecure.

从库上执行:

mysql> CHANGE MASTER TO
-> MASTER_HOST='192.168.56.104',
-> MASTER_PORT=3306,
-> MASTER_USER='rep',
-> MASTER_PASSWORD='1',
-> MASTER_LOG_FILE='mysql-bin.000001',
-> MASTER_LOG_POS=599;
Query OK, 0 rows affected, 2 warnings (0.03 sec)
开启从库
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 192.168.56.104
Master_User: rep
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 599
Relay_Log_File: mysql-s-relay-bin.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: No
Slave_SQL_Running: Yes

但出现了错误,如上图红色,查了一下mysql下的日志,报server UUID相同的错误

2017-11-05T07:12:16.236482Z 6 [ERROR] Slave I/O for channel '': Fatal error: The slave I/O thread stops because master and slave have equal MySQL serve

网上查了一下,是由于虚机复制过来的,两套库uuid相同了,

原因分析:

mysql 5.6的复制引入了uuid的概念,各个复制结构中的server_uuid得保证不一样,但是查看到直接copy  data文件夹后server_uuid是相同的,show variables like '%server_uuid%';

解决方法:

找到data文件夹下的auto.cnf文件,修改里面的uuid值,保证各个db的uuid不一样,重启db即可

[root@mysql-s mysql]# vim auto.cnf
[auto]
server-uuid=ff3d3303-c16d-11e7-b885-080027c5cf4b
把上面uuid最后原来3b-修改为4b重启数据库后,启动从库,成功!!!
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.56.104

Master_User: rep

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000001

Read_Master_Log_Pos: 599

Relay_Log_File: mysql-s-relay-bin.000004

Relay_Log_Pos: 320

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: 599

Relay_Log_Space: 695

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: ff3d3303-c16d-11e7-b885-080027c5cf3b

Master_Info_File: /usr/local/mysql/data/mysql/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: 0

Replicate_Rewrite_DB:

Channel_Name:

Master_TLS_Version:

1 row in set (0.00 sec)

测试主从复制:

在主库上创建aaa数据库:

mysql> create database aaa;
Query OK, 1 row affected (0.01 sec)
查看从库:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| aaa |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.01 sec)

  

  

  

  

  

  

  

  

  

  

  

  

Centos7.3-mysql5.7复制安装过程的更多相关文章

  1. centos7下mysql5.7的安装与配置

    centos7下MySQL5.7的安装与配置 下载 下载地址 根据系统和版本选择红框中的四个RPM包下载即可,然后放到centos7系统中的/opt目录下,等待稍后安装. 安装前的准备 1. 检查系统 ...

  2. CentOS7下MySQL5.7的安装-RPM方式

    Installing MySQL on Linux Using RPM Packages 下载安装包 mysql下载地址:https://dev.mysql.com/downloads/mysql/ ...

  3. mysql5.5编译安装过程(自己总结)

    一,安装过程 //创建mysql安装目录,创建数据存放目录,创建用户和用户组与赋予数据存放目录权限 mkdir -p /usr/local/mysql/ mkdir -p /data/mysql/ g ...

  4. centos7.2 mysql5.5编译安装

    环境 centos7.2 源码包mysql5.5.38 mysql5.5开始,源码配置编译工具configure变成了cmake,所以先要去把cmake装上.并安装make,bison,cmake,g ...

  5. centos7+mono4+jexus5.6.2安装过程中的遇到的问题

    过程参考: http://www.linuxdot.net/ http://www.jexus.org/ http://www.mono-project.com/docs/getting-starte ...

  6. mysql5.7.12安装过程中遇到的一些问题

    在安装mysql-5.7.12-winx64中遇到的问题总结 1.该版本的mysql解压后的文件夹里没有data文件(切记自己添加data,自己添加的文件可能出现的问题是文件里的文件会缺失) 我在使用 ...

  7. Linux MySql5.6.38安装过程

    1.下载mysql安装包mysql-5.6.38-linux-glibc2.12-x86_64.tar.gz 2.用xftp工具将其上传到Linux服务器上的soft文件夹,没有的话先创建 [root ...

  8. MySQL5.7.20安装过程报错CMake Error at cmake/boost.cmake:81 (MESSAGE):

    MySQL在5.7版本及以后,都需要boots 库,所以需要先安装boots 步骤: 1.在/usr/local下创建 名为boots的目录 mkdir -p /usr/local/boots 2.进 ...

  9. 1、linux下mysql5.5.20安装过程报错汇总

    1.Access denied for user 'root'@'localhost' (using password: YES) 这个提示是因为root帐户默认不开放远程访问权限,所以需要修改一下相 ...

随机推荐

  1. golang 程序 在linux 出现 段错误

    刚做的 golang 程序 发布到linux 竟然出现 段错误 原因是 内核版本过低,请升级内核

  2. 在vue项目中正确的引入jquery

    最近学习vue,习惯性的通过<script>标签引入jquery,写完后报错才想起来,这种方式在vue是不适用的. 1:因为已经安装了vue脚手架,所以需要在webpack中全局引入jqu ...

  3. php学习知识点框架

    图片来源于知乎,感觉挺全面,通过查看可以更好的了解自己的薄弱知识点,大家共勉.

  4. 分布式事务 XA 两段式事务 X/open CAP BASE 一次分清

    分布式事务: 分布式事务是处理多节点上 的数据保持 类似传统 ACID 事物特性的 一种事物. XA:是一种协议,一种分布式事务的协议,核心思想是2段式提交. 1 准备阶段  2 提交阶段.XA协议是 ...

  5. Mac系统常用快捷键大全

    苹果Mac系统常用快捷键有很多,但是很多童鞋对于这些mac快捷键都不是很熟悉,今天小编为大家整理了一份Mac系统常用快捷键大全,大家快收藏起来吧!平时在使用mac系统的时候可以提高不少工作效率哦! M ...

  6. day37 04-Hibernate二级缓存:list和iterate方法比较

    get()和load()方法既可以向一级缓存区放数据,也可以向二级缓存区放数据.这是查询一个的情况.要是查询所有呢?注意, // 查询所有.Query接口的list()方法. // list()方法会 ...

  7. TP3.2.x判断手机端访问并设置默认访问模块的方法 - ThinkPHP框架

    手机端访问时调用Wap手机模块,实现在手机端访问时展示出手机网站,无需跳转域名首先我们在./Application/Common/Conf/ 目录下建立两个公共配置文件:config.php 和con ...

  8. bzoj4974: [Lydsy八月月赛]字符串大师

    传送门 题目可转换为已知一个串kmp之后的nxt数组,求字典序最小的原串. 已知第i位结尾的串循环节长度位x,那么nxt[i]=i-x; 当nxt不为0时,s[i]=s[nxt[i]]; nxt为0时 ...

  9. 实践中了解到的CSS样式的优先级

    CSS三大特性——继承.优先级和层叠.这是在精通CSS中重点强调的内容. 继承即子类元素继承父类的样式,常用的可继承样式有:color,font,line-height,list-style,text ...

  10. .NET EasyUI datebox添加清空功能

    前言,前段时间的项目使用EasyUI框架搭建,使用了其自带的一系列组件.但对于datebox,其功能别的不多说,令人蛋疼的是它居然没有清空功能,这让在搜索区域中摆了日期条件的咋整啊,没办法,既然用了这 ...