一、检查当前环境是否安装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;
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。