MySQL启动报错解决

报错内容:

bash 复制代码
[root@k8s-node1 ~]# systemctl start mysqld
Job for mysqld.service failed because the control process exited with error code.
See "systemctl status mysqld.service" and "journalctl -xeu mysqld.service" for details.
[root@k8s-node1 ~]# journalctl -xe mysqld.service 
Failed to add match 'mysqld.service': Invalid argument
[root@k8s-node1 ~]# systemctl status mysqld
● mysqld.service - MySQL Server
     Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
     Active: activating (auto-restart) (Result: exit-code) since Tue 2025-03-11 18:53:48 CST; 106ms ago
       Docs: man:mysqld(8)
             http://dev.mysql.com/doc/refman/en/using-systemd.html
    Process: 654160 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
    Process: 654199 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=1/FAILURE)

使用 journalctl 查看与 mysqld 相关的详细日志输出:

bash 复制代码
[root@k8s-node1 ~]# journalctl -xeu mysqld.service
░░ 
░░ A start job for unit mysqld.service has begun execution.
░░ 
░░ The job identifier is 395576.
Mar 11 18:54:36 k8s-node1 mysqld_pre_systemd[655044]: /usr/bin/mysqld_pre_systemd: line 48: 655064 Killed                  /usr/sbin/mysqld ${instance:+--defaults-group-suffix=@$instance} --initialize --datadir="$datadir" --user=mysql>
Mar 11 18:54:37 k8s-node1 mysqld[655067]: Initialization of mysqld failed: 0
Mar 11 18:54:37 k8s-node1 systemd[1]: mysqld.service: Control process exited, code=exited, status=1/FAILURE
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░ 
░░ An ExecStart= process belonging to unit mysqld.service has exited.
░░ 
░░ The process' exit code is 'exited' and its exit status is 1.
Mar 11 18:54:38 k8s-node1 systemd[1]: mysqld.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░ 
░░ The unit mysqld.service has entered the 'failed' state with result 'exit-code'.
Mar 11 18:54:38 k8s-node1 systemd[1]: Failed to start MySQL Server.
░░ Subject: A start job for unit mysqld.service has failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░ 
░░ A start job for unit mysqld.service has finished with a failure.
░░ 
░░ The job identifier is 395576 and the job result is failed.
Mar 11 18:54:39 k8s-node1 systemd[1]: mysqld.service: Scheduled restart job, restart counter is at 6197.
░░ Subject: Automatic restarting of a unit has been scheduled
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░ 
░░ Automatic restarting of the unit mysqld.service has been scheduled, as the result for
░░ the configured Restart= setting for the unit.
Mar 11 18:54:39 k8s-node1 systemd[1]: Stopped MySQL Server.
░░ Subject: A stop job for unit mysqld.service has finished
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░ 
░░ A stop job for unit mysqld.service has finished.
░░ 
░░ The job identifier is 395639 and the job result is done.
Mar 11 18:54:39 k8s-node1 systemd[1]: Starting MySQL Server...
░░ Subject: A start job for unit mysqld.service has begun execution
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░ 
░░ A start job for unit mysqld.service has begun execution.

可以看出 mysqld 服务在启动过程中失败了,特别是在初始化阶段

解决方法:

bash 复制代码
[root@k8s-node1 ~]# systemctl stop mysqld
[root@k8s-node1 ~]# yum clean all
0 files removed
[root@k8s-node1 ~]# mv /var/lib/mysql /var/lib/mysql_backup
[root@k8s-node1 ~]# mkdir /var/lib/mysql
[root@k8s-node1 ~]# chown mysql:mysql /var/lib/mysql
[root@k8s-node1 ~]# mysqld --initialize --user=mysql --datadir=/var/lib/mysql
[root@k8s-node1 ~]# systemctl restart mysqld
相关推荐
行初心7 分钟前
uos基础 sys-kernel-debug.mount 查看mount文件
运维
b***462411 分钟前
从 SQL 语句到数据库操作
数据库·sql·oracle
Q***f63513 分钟前
后端数据库性能优化的8个工具推荐
数据库·性能优化
一水鉴天35 分钟前
整体设计 定稿 之1 devOps 中台的 结论性表述(豆包助手)
服务器·数据库·人工智能
1***y17839 分钟前
DevOps在云中的Rancher
运维·rancher·devops
vx_dmxq2111 小时前
【微信小程序学习交流平台】(免费领源码+演示录像)|可做计算机毕设Java、Python、PHP、小程序APP、C#、爬虫大数据、单片机、文案
java·spring boot·python·mysql·微信小程序·小程序·idea
q***07141 小时前
Spring Boot 中使用 @Transactional 注解配置事务管理
数据库·spring boot·sql
tianyuanwo1 小时前
多平台容器化RPM构建流水线全指南:Fedora、CentOS与Anolis OS
linux·运维·容器·centos·rpm
m***92381 小时前
【SQL】MySQL中的字符串处理函数:concat 函数拼接字符串,COALESCE函数处理NULL字符串
数据库·sql·mysql
!停2 小时前
VS实用调试技巧
数据库