You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CentOS 9下systemctl启动MySQL 8失败的解决求助

CentOS 9下MySQL 8.0启动失败的解决方案

问题现象

在CentOS 9服务器上安装mysql-community-server后,mysqld.service无法启动,导致无法执行mysql_secure_installation脚本。

排查信息

1. 服务状态输出

执行命令:systemctl status mysqld.service -l

× mysqld.service - MySQL 8.0 database server
     Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; preset: disabled)
     Active: failed (Result: exit-code) since Sun 2023-04-16 16:05:08 WIB; 3min 44s ago
    Process: 175360 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
    Process: 175382 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=1/FAILURE)
    Process: 175453 ExecStopPost=/usr/libexec/mysql-wait-stop (code=exited, status=0/SUCCESS)
        CPU: 302ms

Apr 16 16:05:08 localhost.localdomain systemd[1]: mysqld.service: Scheduled restart job, restart counter is at 5.
Apr 16 16:05:08 localhost.localdomain systemd[1]: Stopped MySQL 8.0 database server.
Apr 16 16:05:08 localhost.localdomain systemd[1]: mysqld.service: Start request repeated too quickly.
Apr 16 16:05:08 localhost.localdomain systemd[1]: mysqld.service: Failed with result 'exit-code'.
Apr 16 16:05:08 localhost.localdomain systemd[1]: Failed to start MySQL 8.0 database server.

2. Systemd日志输出

执行命令:journalctl -xeu mysqld.service

░░ Subject: A stop job for unit mysqld.service has finished
░░ Defined-By: systemd
░░ Support: https://access.redhat.com/support
░░
░░ A stop job for unit mysqld.service has finished.
░░
░░ The job identifier is 2522 and the job result is done.
Apr 16 16:05:08 localhost.localdomain systemd[1]: mysqld.service: Start request repeated too quickly.
Apr 16 16:05:08 localhost.localdomain systemd[1]: mysqld.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://access.redhat.com/support
░░
░░ The unit mysqld.service has entered the 'failed' state with result 'exit-code'.
Apr 16 16:05:08 localhost.localdomain systemd[1]: Failed to start MySQL 8.0 database server.
░░ Subject: A start job for unit mysqld.service has failed
░░ Defined-By: systemd
░░ Support: https://access.redhat.com/support
░░
░░ A start job for unit mysqld.service has finished with a failure.
░░
░░ The job identifier is 2522 and the job result is failed.

3. MySQL日志输出

查看/var/log/mysqld.log:

2023-04-16T07:09:36.513801Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.32) starting as process 3184883
2023-04-16T07:09:36.521011Z 1 [System] [MY-011012] [Server] Starting upgrade of data directory.
2023-04-16T07:09:36.521100Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-04-16T07:09:36.546249Z 1 [ERROR] [MY-012224] [InnoDB] Tablespace flags are invalid in datafile: ./ibdata1, Space ID:0, Flags: 21. Please refer to http://dev.mysql.com/doc/refman/8.0/en/innodb-troubleshooting-datadict.html for how to resolve the issue.
2023-04-16T07:09:36.546323Z 1 [ERROR] [MY-012237] [InnoDB] Corrupted page [page id: space=0, page number=0] of datafile './ibdata1' could not be found in the doublewrite buffer.
2023-04-16T07:09:36.546341Z 1 [ERROR] [MY-012960] [InnoDB] Cannot create redo log files because data files are corrupt or the database was not shut down cleanly after creating the data files.
2023-04-16T07:09:37.045862Z 1 [ERROR] [MY-011013] [Server] Failed to initialize DD Storage Engine.
2023-04-16T07:09:37.046219Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2023-04-16T07:09:37.046306Z 0 [ERROR] [MY-010119] [Server] Aborting
2023-04-16T07:09:37.047051Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.32)  MySQL Community Server - GPL.

问题原因

核心问题是ibdata1文件损坏,导致InnoDB存储引擎无法初始化,最终MySQL服务启动失败。该情况通常由MySQL实例未正常关闭、磁盘故障或安装异常导致。

解决步骤

注意:以下操作会清除所有现有MySQL数据,如有重要数据请先备份!

  • 停止MySQL服务

    systemctl stop mysqld.service
    
  • 备份数据目录(可选)
    若需保留数据痕迹,执行备份:

    cp -r /var/lib/mysql /var/lib/mysql_backup_$(date +%Y%m%d)
    
  • 删除损坏的数据文件
    清空MySQL默认数据目录:

    rm -rf /var/lib/mysql/*
    
  • 重新初始化MySQL
    生成新的系统表和数据文件:

    mysqld --initialize --user=mysql
    
  • 启动MySQL服务

    systemctl start mysqld.service
    
  • 验证服务状态

    systemctl status mysqld.service
    

    确认服务状态为active (running)。

  • 执行安全配置
    此时可正常运行安全配置脚本:

    mysql_secure_installation
    

    初始化后的临时密码可通过以下命令查看:

    grep 'temporary password' /var/log/mysqld.log
    

内容的提问来源于stack exchange,提问作者Raditya Pratama

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 22:12:55