一、查看以后环境是否装置 MySQL,如有装置 MySQL 或者 Mariadb,能够卸载;
rpm -qa | grep mysql
pm -qa |grep mariadb
yum remove mariadb-libs-5.5.64-1.el7.x86_64
二、下载并装置
1、国内用户思考切换 yum 源为阿里云;
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
yum update -y
2、下载对应版本的 MySQL RPM 安装包,下载地址 http://mirrors.ustc.edu.cn/mysql-ftp/Downloads
# server 包
wget https://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/mysql-community-server-5.7.31-1.el7.x86_64.rpm
# client 包
wget http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/mysql-community-client-5.7.31-1.el7.x86_64.rpm
# common 包
wget http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/mysql-community-common-5.7.31-1.el7.x86_64.rpm
# lib 包
wget http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/mysql-community-libs-5.7.31-1.el7.x86_64.rpm
3、装置依赖包
yum install -y perl libaio net-tools
4、装置对应版本的 MySQL(按程序)
rpm -ivh mysql-community-common-5.7.31-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-libs-5.7.31-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-client-5.7.31-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.31-1.el7.x86_64.rpm
5、启动 MySQL
systemctl start mysqld.service
systemctl status mysqld.service
6、登陆 MySQL 更新默认明码,
# 获取默认 root 明码
cat /var/log/mysqld.log | grep 'password'
# 登陆 mysql,更改默认明码
mysql -u root -p
set password=password('xxxxxx')
# 开启近程连贯
use mysql;
update user set Host = '%' where Host = 'localhost' and User='root';
flush privileges;