MYSQL-5.7.20的安装和主从配置(rpm安装包)
Posted 狂飙的蜗牛
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MYSQL-5.7.20的安装和主从配置(rpm安装包)相关的知识,希望对你有一定的参考价值。
一,下载解压(包含全部的rpm包)
如果防火墙有屏蔽,先安装rz
yum install lrzsz -y
再在本地下载,再上传 https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar
二,安装
安装的过程如果和mariadb包有冲突,如果要有先卸载
rpm -qa|grep mariadb
查看已安装的mariadb包
rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64 rpm -e --nodeps mariadb-5.5.44-2.el7.centos.x86_64 rpm -e --nodeps mariadb-devel-5.5.44-2.el7.centos.x86_64
依次先后安装
rpm -ivh mysql/mysql-community-common-5.7.20-1.el7.x86_64.rpm rpm -ivh mysql/mysql-community-libs-5.7.20-1.el7.x86_64.rpm rpm -ivh mysql/mysql-community-client-5.7.20-1.el7.x86_64.rpm rpm -ivh mysql/mysql-community-server-5.7.20-1.el7.x86_64.rpm
三,配置/etc/my.cnf 文件
[mysqld] character-set-server=utf8 [mysql] default-character-set = utf8 [mysql.server] default-character-set = utf8 [mysqld_safe] default-character-set = utf8 [client] default-character-set = utf8
查看修改后的效果
SHOW VARIABLES LIKE ‘character%‘;
四,初始化mysql
mysqld --initialize --user=mysql 如有必要指定路径可以加上下面的参数 --basedir=/usr/local/mysql --datadir=/data/mysql
root 用户随机密码保留在/var/log/mysqld.log 文件中
五,启动mysql
systemctl start mysqld (启动mysql)
systemctl restart mysqld (重启mysql)
systemctl status mysqld (查看状态)
六,修改root 初始密码
mysql -u root -p (使用刚才的随机密码)
或者 使用下面命令初始化mysql,则不需要密码登录
mysqld --initialize-insecure --user=mysql mysql -u root --skip-password alter user ‘root‘@‘localhost‘ identified by ‘pwd456‘;
如果无法登录,再修改/etc/my.cnf 文件 加入以下参数
skip-grant-tables
再 systemctl restart mysqld (重启mysql) 就可以无密码登录了,修改密码
update user set authentication_string=password("pwd456") where user="root"; flush privileges;
七,配置主从
1,修改master /etc/my.cnf 文件
log-bin=mysql-bin server-id=1 --------下面可以忽略 binlog-ignore-db=information_schema binlog-ignore-db=mysql -----------------------
2,登录master
GRANT FILE ON *.* TO [email protected]‘xx.xx.xx.xx‘ IDENTIFIED BY ‘pwd123‘; GRANT REPLICATION SLAVE,RELOAD,SUPER ON *.* TO [email protected]‘xx.xx.xx.xx‘ IDENTIFIED BY ‘pwd123‘; 查看状态 SHOW MASTER STATUS G;
3,修改slave的配置 /etc/my.cnf 文件
log-bin=mysql-bin (非必须项,当slave需要同步的时候才必须) server-id=2 log_slave_updates = 1 read_only = 1 slave-skip-errors = all slave-net-timeout = 60 --------下面可以忽略 binlog-ignore-db=information_schema binlog-ignore-db=cluster binlog-ignore-db=mysql replicate-do-db=ufind_db replicate-ignore-db=mysql
4,修改同步选项, 重启slave
change master to master_host=‘xx.xx.xx.01‘,master_user=‘replicate‘,master_password=‘pwd123‘,master_log_file=‘mysql-bin.000001‘, master_log_pos=760;
查看 slave 状态
START SLAVE;
SHOW SLAVE STATUS G;
可以看到
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
参考
mysql的安装 参考 https://jingyan.baidu.com/article/93f9803f010d8fe0e56f555e.html
以上是关于MYSQL-5.7.20的安装和主从配置(rpm安装包)的主要内容,如果未能解决你的问题,请参考以下文章
MySQL 5.7.20在RedHat 7.2上通过RPM包安装