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
相关推荐
啦啦啦_99993 小时前
Redis-2-queryFormat()方法
数据库·redis·缓存
阿梦Anmory4 小时前
Ubuntu配置代理最详细教程
linux·运维·ubuntu
呉師傅4 小时前
【使用技巧】Adobe Photoshop 2024调整缩放与布局125%后出现点菜单项漂移问题的简单处理
运维·服务器·windows·adobe·电脑·photoshop
heartbeat..4 小时前
JVM 性能调优流程实战:从开发规范到生产应急排查
java·运维·jvm·性能优化·设计规范
玄同7654 小时前
SQLite + LLM:大模型应用落地的轻量级数据存储方案
jvm·数据库·人工智能·python·语言模型·sqlite·知识图谱
吾日三省吾码4 小时前
别只会“加索引”了!这 3 个 PostgreSQL 反常识优化,能把性能和成本一起打下来
数据库·postgresql
chian-ocean4 小时前
百万级图文检索实战:`ops-transformer` + 向量数据库构建语义搜索引擎
数据库·搜索引擎·transformer
那个村的李富贵5 小时前
解锁CANN仓库核心能力:50行代码搭建国产化AIGC图片风格迁移神器
mysql·信息可视化·aigc·cann
小Tomkk5 小时前
数据库 变更和版本控制管理工具 --Bytebase 安装部署(linux 安装篇)
linux·运维·数据库·ci/cd·bytebase
赌博羊5 小时前
ImportError: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32‘ not found
linux·运维·gnu