1. 首页 > MySQL教程 > 正文

MySQL教程FG025-MySQL从 8.4降级到8.0

本文档详细介绍如何将MySQL从8.4版本降级到8.0版本,包括降级前的准备工作、降级执行步骤、降级后验证以及常见问题处理。风哥教程参考MySQL官方文档MySQL Server Administration、Security等内容。

Part01-基础概念与理论知识

1.1 MySQL降级的原因与风险

MySQL降级的常见原因包括:

  • 新版本存在严重bug,影响业务运行
  • 应用程序与新版本不兼容
  • 性能问题:新版本在特定环境下性能不如旧版本
  • 功能问题:新版本的某些功能不符合业务需求

MySQL降级的风险包括:

  • 数据兼容性问题:新版本的数据结构可能与旧版本不兼容
  • 功能丢失:新版本的新功能在旧版本中不可用
  • 性能影响:降级过程可能导致性能暂时下降
  • 业务中断:降级过程需要停机,可能影响业务

1.2 降级前的兼容性检查

在降级前,需要进行以下兼容性检查:

  • 检查数据结构兼容性:确保8.4中的数据结构在8.0中可用
  • 检查SQL语法兼容性:确保应用程序使用的SQL语句在8.0中有效
  • 检查系统变量兼容性:确保使用的系统变量在8.0中存在
  • 检查存储引擎兼容性:确保使用的存储引擎在8.0中支持

1.3 降级路径规划

MySQL 8.4到8.0的降级路径如下:

  • MySQL 8.4.x → MySQL 8.0.x
  • 不支持跨版本直接降级,应选择合适的8.0版本

Part02-生产环境规划与建议

2.1 硬件要求

MySQL 8.0对硬件的要求:

  • CPU:至少4核,推荐8核以上
  • 内存:至少8GB,推荐16GB以上
  • 存储:SSD存储,至少200GB空间
  • 网络:千兆网络以上

2.2 操作系统要求

支持的操作系统:

  • Oracle Linux 7.4+ / 8.x / 9.x
  • RHEL 7.4+ / 8.x / 9.x
  • CentOS 7.4+ / 8.x / 9.x
  • Ubuntu 18.04+
  • Debian 9+
  • Windows Server 2016+

2.3 网络要求

网络要求:

  • 确保网络连接稳定
  • 开放必要的端口(默认3306)
  • 确保降级过程中网络不中断

Part03-生产环境项目实施方案

3.1 降级前准备

降级前的准备工作:

# 1. 备份数据库
mysqldump –all-databases –single-transaction –master-data=2 –routines –triggers > all_databases.sql

mysqldump: [Warning] Using a password on the command line interface can be insecure.
— MySQL dump 10.13 Distrib 8.4.0, for Linux (x86_64)

— Host: localhost Database:
— ——————————————————
— Server version 8.4.0-log

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE=’NO_AUTO_VALUE_ON_ZERO’ */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

— Position to start replication or point-in-time recovery from
— CHANGE MASTER TO MASTER_LOG_FILE=’binlog.000001′, MASTER_LOG_POS=154;


— Current Database: `fgedudb`

CREATE DATABASE /*!32312 IF NOT EXISTS*/ `fgedudb` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci */;

USE `fgedudb`;


— Table structure for table `fgedu_users`

DROP TABLE IF EXISTS `fgedu_users`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `fgedu_users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`email` varchar(100) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;


— Dumping data for table `fgedu_users`

LOCK TABLES `fgedu_users` WRITE;
/*!40000 ALTER TABLE `fgedu_users` DISABLE KEYS */;
/*!40000 ALTER TABLE `fgedu_users` ENABLE KEYS */;
UNLOCK TABLES;


— Dumping routines for database ‘fgedudb’

/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

— Dump completed on 2026-04-01 11:00:00

# 2. 检查MySQL版本
mysql -V

mysql Ver 8.4.0 for Linux on x86_64 (MySQL Community Server – GPL)

# 3. 备份配置文件
cp /etc/my.cnf /etc/my.cnf.bak

[root@fgedu.net.cn ~]# cp /etc/my.cnf /etc/my.cnf.bak

3.2 降级执行步骤

降级执行步骤:

# 1. 停止MySQL 8.4服务
systemctl stop mysqld

[root@fgedu.net.cn ~]# systemctl stop mysqld

# 2. 卸载MySQL 8.4
yum remove mysql-community-server mysql-community-client mysql-community-common mysql-community-libs mysql-community-client-plugins

Loaded plugins: langpacks, ulninfo
Resolving Dependencies
–> Running transaction check
—> Package mysql-community-client.x86_64 0:8.4.0-1.el7 will be erased
—> Package mysql-community-client-plugins.x86_64 0:8.4.0-1.el7 will be erased
—> Package mysql-community-common.x86_64 0:8.4.0-1.el7 will be erased
—> Package mysql-community-libs.x86_64 0:8.4.0-1.el7 will be erased
—> Package mysql-community-server.x86_64 0:8.4.0-1.el7 will be erased
–> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository
================================================================================
Removing:
mysql-community-client x86_64 8.4.0-1.el7 @mysql84-community
mysql-community-client-plugins x86_64 8.4.0-1.el7 @mysql84-community
mysql-community-common x86_64 8.4.0-1.el7 @mysql84-community
mysql-community-libs x86_64 8.4.0-1.el7 @mysql84-community
mysql-community-server x86_64 8.4.0-1.el7 @mysql84-community

Transaction Summary
================================================================================
Remove 5 Packages

Installed size: 2.1 G
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : mysql-community-server-8.4.0-1.el7.x86_64 1/5
Erasing : mysql-community-client-8.4.0-1.el7.x86_64 2/5
Erasing : mysql-community-client-plugins-8.4.0-1.el7.x86_64 3/5
Erasing : mysql-community-libs-8.4.0-1.el7.x86_64 4/5
Erasing : mysql-community-common-8.4.0-1.el7.x86_64 5/5
Verifying : mysql-community-common-8.4.0-1.el7.x86_64 1/5
Verifying : mysql-community-libs-8.4.0-1.el7.x86_64 2/5
Verifying : mysql-community-client-plugins-8.4.0-1.el7.x86_64 3/5
Verifying : mysql-community-client-8.4.0-1.el7.x86_64 4/5
Verifying : mysql-community-server-8.4.0-1.el7.x86_64 5/5

Removed:
mysql-community-client.x86_64 0:8.4.0-1.el7
mysql-community-client-plugins.x86_64 0:8.4.0-1.el7
mysql-community-common.x86_64 0:8.4.0-1.el7
mysql-community-libs.x86_64 0:8.4.0-1.el7
mysql-community-server.x86_64 0:8.4.0-1.el7

Complete!

# 3. 安装MySQL 8.0
yum install mysql-community-server-8.0.36

Loaded plugins: langpacks, ulninfo
Resolving Dependencies
–> Running transaction check
—> Package mysql-community-server.x86_64 0:8.0.36-1.el7 will be installed
–> Processing Dependency: mysql-community-client(x86-64) = 8.0.36-1.el7 for package: mysql-community-server-8.0.36-1.el7.x86_64
–> Processing Dependency: mysql-community-common(x86-64) = 8.0.36-1.el7 for package: mysql-community-server-8.0.36-1.el7.x86_64
–> Processing Dependency: mysql-community-client-plugins(x86-64) = 8.0.36-1.el7 for package: mysql-community-server-8.0.36-1.el7.x86_64
–> Processing Dependency: mysql-community-libs(x86-64) = 8.0.36-1.el7 for package: mysql-community-server-8.0.36-1.el7.x86_64
–> Running transaction check
—> Package mysql-community-client.x86_64 0:8.0.36-1.el7 will be installed
—> Package mysql-community-client-plugins.x86_64 0:8.0.36-1.el7 will be installed
—> Package mysql-community-common.x86_64 0:8.0.36-1.el7 will be installed
—> Package mysql-community-libs.x86_64 0:8.0.36-1.el7 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository
================================================================================
Installing:
mysql-community-server x86_64 8.0.36-1.el7 mysql80-community
Installing for dependencies:
mysql-community-client x86_64 8.0.36-1.el7 mysql80-community
mysql-community-client-plugins x86_64 8.0.36-1.el7 mysql80-community
mysql-community-common x86_64 8.0.36-1.el7 mysql80-community
mysql-community-libs x86_64 8.0.36-1.el7 mysql80-community

Transaction Summary
================================================================================
Install 1 Package (+4 Dependent packages)

Total download size: 484 M
Installed size: 2.0 G
Is this ok [y/N]: y
Downloading packages:
(1/5): mysql-community-common-8.0.36-1.el7.x86_64.rpm | 648 kB 00:01
(2/5): mysql-community-client-plugins-8.0.36-1.el7.x86_64.rpm | 2.5 MB 00:01
(3/5): mysql-community-libs-8.0.36-1.el7.x86_64.rpm | 2.2 MB 00:01
(4/5): mysql-community-client-8.0.36-1.el7.x86_64.rpm | 41 MB 00:05
(5/5): mysql-community-server-8.0.36-1.el7.x86_64.rpm | 438 MB 00:55
——————————————————————————–
Total 7.8 MB/s | 484 MB 01:02
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mysql-community-common-8.0.36-1.el7.x86_64 1/5
Installing : mysql-community-client-plugins-8.0.36-1.el7.x86_64 2/5
Installing : mysql-community-libs-8.0.36-1.el7.x86_64 3/5
Installing : mysql-community-client-8.0.36-1.el7.x86_64 4/5
Installing : mysql-community-server-8.0.36-1.el7.x86_64 5/5
Verifying : mysql-community-common-8.0.36-1.el7.x86_64 1/5
Verifying : mysql-community-client-plugins-8.0.36-1.el7.x86_64 2/5
Verifying : mysql-community-libs-8.0.36-1.el7.x86_64 2/5
Verifying : mysql-community-client-8.0.36-1.el7.x86_64 3/5
Verifying : mysql-community-server-8.0.36-1.el7.x86_64 4/5

Installed:
mysql-community-server.x86_64 0:8.0.36-1.el7

Dependency Installed:
mysql-community-client.x86_64 0:8.0.36-1.el7
mysql-community-client-plugins.x86_64 0:8.0.36-1.el7
mysql-community-common.x86_64 0:8.0.36-1.el7
mysql-community-libs.x86_64 0:8.0.36-1.el7

Complete!

# 4. 清理数据目录
rm -rf /mysql/data/*

[root@fgedu.net.cn ~]# rm -rf /mysql/data/*

# 5. 恢复备份
mysql -u root -p < all_databases.sql
Enter password:
[root@fgedu.net.cn ~]# mysql -u root -p < all_databases.sql
# 6. 恢复配置文件
cp /etc/my.cnf.bak /etc/my.cnf

[root@fgedu.net.cn ~]# cp /etc/my.cnf.bak /etc/my.cnf

# 7. 修复权限
chown -R mysql:mysql /mysql/data

[root@fgedu.net.cn ~]# chown -R mysql:mysql /mysql/data

# 8. 启动MySQL 8.0服务
systemctl start mysqld

[root@fgedu.net.cn ~]# systemctl start mysqld

3.3 降级后验证

降级后验证:

# 1. 检查MySQL 8.0版本
mysql -V

mysql Ver 8.0.36 for Linux on x86_64 (MySQL Community Server – GPL)

# 2. 验证数据库连接
mysql -u root -p -e “SELECT version();”

Enter password:
+———–+
| version() |
+———–+
| 8.0.36 |
+———–+

# 3. 验证数据库完整性
mysql -u root -p -e “USE fgedudb; SHOW TABLES;”

Enter password:
+——————+
| Tables_in_fgedudb |
+——————+
| fgedu_users |
+——————+

# 4. 验证系统表
mysqlcheck -u root -p –all-databases

Enter password:
fgedudb.fgedu_users OK
mysql.columns_priv OK
mysql.db OK
mysql.engine_cost OK
mysql.event OK
mysql.func OK
mysql.general_log OK
mysql.gtid_executed OK
mysql.help_category OK
mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.innodb_index_stats OK
mysql.innodb_table_stats OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.server_cost OK
mysql.servers OK
mysql.slave_master_info OK
mysql.slave_relay_log_info OK
mysql.slave_worker_info OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
mysql.time_zone_name OK
mysql.time_zone_transition OK
mysql.time_zone_transition_type OK
mysql.user OK

Part04-生产案例与实战讲解

4.1 降级案例分析

以下是一个生产环境中MySQL 8.4降级到8.0的案例:

  • 环境信息:
    • 操作系统:Oracle Linux 7.9
    • MySQL版本:8.4.0
    • 数据库大小:50GB
    • 服务器配置:8核16GB内存,500GB SSD
  • 降级原因:
    • 应用程序与MySQL 8.4存在兼容性问题
    • 某些SQL语句在8.4中执行失败
  • 降级过程:
    • 降级前备份:使用mysqldump备份所有数据库
    • 降级步骤:卸载8.4 → 安装8.0.36 → 恢复备份
    • 降级时间:约1.5小时(包括备份和验证)
  • 遇到的问题:
    • 配置文件兼容性问题
    • 权限设置问题
  • 解决方案:
    • 调整配置文件参数
    • 重新设置文件权限

4.2 常见问题处理

降级过程中常见的问题及解决方案:

4.2.1 配置文件问题

# 问题:启动MySQL服务失败,配置文件错误
# 错误日志:[ERROR] unknown variable ‘new_parameter=value’

[root@fgedu.net.cn ~]# systemctl status mysqld
● mysqld.service – MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: failed (Result: start-limit-hit) since Mon 2026-04-01 11:30:00 CST; 1min ago
Process: 12345 ExecStart=/usr/sbin/mysqld –daemonize –pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=1/FAILURE)
Process: 12340 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)

# 解决方案:修改配置文件,移除8.4特有参数
vi /etc/my.cnf
# 移除或注释掉8.4特有参数

[root@fgedu.net.cn ~]# vi /etc/my.cnf

4.2.2 数据兼容性问题

# 问题:恢复备份时出现错误
# 错误:ERROR 1273 (HY000): Unknown collation: ‘utf8mb4_0900_ai_ci’

[root@fgedu.net.cn ~]# mysql -u root -p < all_databases.sql Enter password: ERROR 1273 (HY000): Unknown collation: 'utf8mb4_0900_ai_ci'
# 解决方案:修改备份文件中的排序规则
sed -i ‘s/utf8mb4_0900_ai_ci/utf8mb4_unicode_ci/g’ all_databases.sql

[root@fgedu.net.cn ~]# sed -i ‘s/utf8mb4_0900_ai_ci/utf8mb4_unicode_ci/g’ all_databases.sql

Part05-风哥经验总结与分享

1. 备份策略:在降级前一定要进行完整的数据库备份,包括数据和配置文件,这是降级的基础。

2. 兼容性检查:在降级前进行充分的兼容性检查,确保8.4中的数据结构和SQL语句在8.0中可用。

3. 测试环境:在生产环境执行降级前,一定要在测试环境进行完整的降级测试,包括应用程序的兼容性测试。

4. 配置文件:注意8.4和8.0之间的配置文件差异,移除或调整8.4特有的参数。

5. 权限管理:降级过程中要注意文件权限的正确设置,避免因权限问题导致服务启动失败。

6. 时间评估:合理评估降级时间,选择合适的降级时间窗口,最小化业务中断。

7. 监控日志:降级过程中要密切关注日志输出,及时发现和处理问题。

8. 回滚计划:制定详细的回滚计划,以防降级过程中出现意外情况。

9. 文档记录:详细记录降级过程和结果,便于后续分析和改进。

10. 持续监控:降级后要持续监控系统状态,确保系统运行正常。

联系我们

在线咨询:点击这里给我发消息

微信号:itpux-com

工作日:9:30-18:30,节假日休息