1、配置YUM源
在MySQL官网中下载YUM源rpm安装包:https://dev.mysql.com/downloads/repo/yum/
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
安装mysql源
yum localinstall mysql57-community-release-el7-8.noarch.rpm
检查mysql源是否安装成功
yum repolist enabled | grep "mysql.*-community.*"

2、安装MySQL
yum install mysql-community-server
3、启动MySQL服务
systemctl start mysqld
4、开机启动
systemctl enable mysqld
systemctl daemon-reload
5、修改root本地登录密码
mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:
set password for ‘root‘@‘localhost‘=password(‘password!‘);

6、允许远程连接
grant all on *.* to root@‘%‘ identified by ‘password‘ with grant option; flush privileges;
卸载
采用yum安装mysql后,如果想要完全卸载mysql,可以采用如下方式:
1、查看mysql安装了哪些东西
rpm -qa |grep -i mysql

2、开始卸载
yum remove mysql-community-common-5.7.20-1.el7.x86_64
yum remove mysql-community-client-5.7.20-1.el7.x86_64
yum remove mysql57-community-release-el7-11.noarch
yum remove mysql-community-libs-5.7.20-1.el7.x86_64
yum removemysql-community-server-5.7.20-1.el7.x86_64
3、查看是否卸载完成

4、查找mysql相关目录
find / -name mysql

5、删除相关目录
rm -rf

6、删除/etc/my.cnf
rm -rf /etc/my.cnf
7、删除/var/log/mysqld.log(如果不删除这个文件,会导致新安装的mysql无法生存新密码,导致无法登陆)
rm -rf /var/log/mysqld.log