CentOS 7 安装 MySQL 8.0 踩坑全记录与终极解决方案

一、问题复盘:从报错到根因定位

1. 初始问题:MySQL 官方源安装超时

执行命令 yum -y install https://repo.mysql.com//mysql80-community-release-el7-7.noarch.rpm 时,反复报错:

bash 复制代码
[root@iZ0jlgpxxeb31ngiadjy9gZ java]#  yum -y install https://repo.mysql.com//mysql80-community-release-el7-7.noarch.rpm
Last metadata expiration check: 4:13:36 ago on Wed 13 May 2026 07:44:59 AM CST.
[MIRROR] mysql80-community-release-el7-7.noarch.rpm: Curl error (28): Timeout was reached for https://repo.mysql.com/mysql80-community-release-el7-7.noarch.rpm [Connection timed out after 30000 milliseconds]
[MIRROR] mysql80-community-release-el7-7.noarch.rpm: Curl error (28): Timeout was reached for https://repo.mysql.com/mysql80-community-release-el7-7.noarch.rpm [Connection timed out after 30000 milliseconds]
[MIRROR] mysql80-community-release-el7-7.noarch.rpm: Curl error (28): Timeout was reached for https://repo.mysql.com/mysql80-community-release-el7-7.noarch.rpm [Connection timed out after 30001 milliseconds]
[MIRROR] mysql80-community-release-el7-7.noarch.rpm: Curl error (28): Timeout was reached for https://repo.mysql.com/mysql80-community-release-el7-7.noarch.rpm [Connection timed out after 30000 milliseconds]
[FAILED] mysql80-community-release-el7-7.noarch.rpm: Curl error (28): Timeout was reached for https://repo.mysql.com/mysql80-community-release-el7-7.noarch.rpm [Connection timed out after 30000 milliseconds]
Curl error (28): Timeout was reached for https://repo.mysql.com/mysql80-community-release-el7-7.noarch.rpm [Connection timed out after 30000 milliseconds]
[root@iZ0jlgpxxeb31ngiadjy9gZ java]#

二、分步解决方案:从排查到安装

测试域名解析与连接

bash 复制代码
ping repo.mysql.com
curl -v https://repo.mysql.com

如果无法 ping 通,说明服务器无法访问该域名,优先使用国内源。

失败了

使用阿里云镜像源(最稳定)

直接替换为国内镜像,彻底解决超时问题:

清理之前失败的安装

bash 复制代码
yum remove -y mysql80-community-release-el7-7.noarch

rm -rf /etc/yum.repos.d/mysql-community*

配置阿里云 MySQL 8.0 源

bash 复制代码
cat > /etc/yum.repos.d/mysql-community.repo << EOF
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=https://mirrors.aliyun.com/mysql/yum/mysql80-community/el/7/x86_64/
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/mysql/RPM-GPG-KEY-mysql-2022
EOF

导入 GPG 密钥并刷新缓存

bash 复制代码
rpm --import https://mirrors.aliyun.com/mysql/RPM-GPG-KEY-mysql-2022

yum clean all && yum makecache

linux 安装mysql8




相关推荐
dinglu1030DL1 小时前
SQL嵌套查询逻辑重构_将复杂业务逻辑移至应用层
jvm·数据库·python
2401_884454151 小时前
SQL窗口函数解决数据倾斜问题_如何优化分组查询
jvm·数据库·python
2401_850491651 小时前
Go 中使用 go-json-rest 时调用 Write 方法的正确方式
jvm·数据库·python
2301_815901971 小时前
PHP怎么记录SQL日志_PDOStatement拦截查询语句【详解】
jvm·数据库·python
码农刚子1 小时前
.NET 8 Web开发入门(四):注入燃料——Entity Framework Core 与 Code First 实战
数据库·orm·sql server
承渊政道1 小时前
从ROWNUM到LIMIT:KES、Oracle与PostgreSQL的执行顺序差异解析
数据库·数据仓库·sql·mysql·安全·postgresql·oracle
2501_901006471 小时前
CSS如何实现多种颜色的线性渐变_使用linear-gradient()按方向和色标填色
jvm·数据库·python
2303_821287381 小时前
Golang怎么用embed嵌入SQL文件_Golang如何将SQL迁移文件嵌入Go程序统一管理【技巧】
jvm·数据库·python
m0_702036531 小时前
PHP怎么处理Eloquent Attribute Harmonization属性协调_Laravel解决数据冲突【教程】
jvm·数据库·python