清华大学的镜像站下载https://mirrors.tuna.tsinghua.edu.cn

我的是——mysql80-community-release-el7-1.noarch.rpm

1、以下链接复制到浏览器地址栏可直接下载哦😊

https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-8.0-community-el7-x86_64/mysql80-community-release-el7-1.noarch.rpm

2、然后把下载完的传到linux(Xftp6为例,左为本地电脑,右为linux,找到直接拖进去)

3、安装命令

yum -y install mysql80-community-release-el8-1.noarch.rpm
yum -y install mysql-community-server

4、安装完毕后运行mysql

service mysql start

5、如果报错Failed to start mysql.service: Unit not found
首先看一下服务列表里有没有这个服务:

systemctl list-unit-files --type=service

可能是只有mysqld.service,没有mysql.service
就用以下启动

service mysqld start

6、登录

mysql -uroot -p

7、进入/var/log/mysqld.log

cd /var/log/mysqld.log

8、找到密码,在A temporary password后面(不找也可以,因为下一步就要改密码了)

9、然后用以下更改密码

alter user '用户名'@'主机名' identified by '新密码';

10、可能会报错说密码不符合策略
那么我们就来改一下策略

mysql8默认密码长度要求为8,安全等级为MEDIUM

11、改一下:

MySql8

set global validate_password.policy=LOW;//改密码等级
set global validate_password.length=8;//改规定密码长度

MySql5.7

set global validate_password_policy=LOW;
set global validate_password_length=8;


如果不能链接:
mysql>执行:

use mysql //切换到mysql库
update user set host = '%' where user = 'root'; //打开root任何地方的访问权限
FLUSH PRIVILEGES; //刷新

再次连接