1、去官网选一款适合的yum源
官网链接:https://dev.mysql.com/downloads/repo/yum/
2、安装MySQL 8.0的yum源
yum install -y https://repo.mysql.com//mysql80-community-release-el8-9.noarch.rpm
如果报如下错误则需要重新设置镜像仓库: ● Status code: 404 for http://mirrors.cloud.aliyuncs.com/centos/8/BaseOS/x86_64/os/repodata/repomd.xml (IP: 100.100.2.148) 错误:为仓库 ‘base’ 下载元数据失败 : Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
此处设置腾讯镜像,官网帮助文档 :https://mirrors.tencent.com/help/centos.html
2.1 备份系统旧的配置文件,注:文件名可能不同
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2.2 获取对应版本的CentOS-Base.repo 到/etc/yum.repos.d/目录
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos8_base.repo
2.3 更新缓存
yum clean all
yum makecache
3、安装MySQL 8.0
yum install mysql-community-server -y
4、启动mysql,并设置开机自启动
systemctl start mysqld systemctl enable mysqld
5、查看临时密码
grep 'temporary password' /var/log/mysqld.log
6、根据临时密码登录后修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'xxxx';
7、开放3306端口
8、配置远程访问权限
CREATE USER 'root'@'%' IDENTIFIED BY 'PASSWORD';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;