你是否遇见以下问题在MySQL重启时出现问题,报出了以下的错误,现在我将告诉你遇见以下错误怎么处理。
[root@C_150 mysql]# systemctl restart mysqldJob for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
当出现了上面的错误,我们可以看出它提供了两条命令“systemctl status mysqld.service”和“journalctl -xe”来帮助我们来查看错误的详情。
使用“systemctl status mysqld.service”命令,可能你看不懂下面密密麻麻的出现的在说什么,但是我们主要看的就是MySQL的状态,我现在的状态就是deactivating,显然服务没开启。然后你只需要看error是什么报错。
[root@C_150 mysql]# systemctl status mysqld.service● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: deactivating (stop-sigterm) (Result: exit-code) Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.htmlProcess: 76588 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=1/FAILURE)Process: 76561 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)Tasks: 23 CGroup: /system.slice/mysqld.service └─76591 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pidDec 23 04:27:18 C_150 systemd[1]: mysqld.service holdoff time over, scheduling restart.Dec 23 04:27:18 C_150 systemd[1]: Stopped MySQL Server.Dec 23 04:27:18 C_150 systemd[1]: Starting MySQL Server...Dec 23 04:27:19 C_150 mysqld_pre_systemd[76561]: 2022-12-22T20:27:19.330849Z 0 [Warning] TIMESTAMP with implicit DEFAULT value i...ails).Dec 23 04:27:19 C_150 mysqld_pre_systemd[76561]: 2022-12-22T20:27:19.331670Z 0 [ERROR] --initialize specified but the data direc...rting.Dec 23 04:27:19 C_150 mysqld_pre_systemd[76561]: 2022-12-22T20:27:19.331687Z 0 [ERROR] AbortingDec 23 04:27:19 C_150 systemd[1]: mysqld.service: control process exited, code=exited status=1Hint: Some lines were ellipsized, use -l to show in full.
找到了error就知道了报错信息, 我们这两句都有error
Dec 23 04:27:19 C_150 mysqld_pre_systemd[76561]: 2022-12-22T20:27:19.331670Z 0 [ERROR] –initialize specified but the data direc…rting.
Dec 23 04:27:19 C_150 mysqld_pre_systemd[76561]: 2022-12-22T20:27:19.331687Z 0 [ERROR] Aborting
没关系我们继续执行另一条命令
[root@C_150 mysql]# journalctl -xe...2022-12-25T01:59:21.237781Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.2022-12-25T01:59:21.239775Z 0 [ERROR] Aborting...
前面的都可以不用查看,看到error报错信息提示来判断错误原因。“initialize specified but the data directory has files in it.”意思是初始化数据目录时发现目录里面有文件,可能原因是之前运行过命令目录中已生成文件。只要我们找到MySQL的数据目录并删除里面的文件即可解决。
查看MySQL指定的数据目录存放路径# cat /etc/my.cnf......省略内容...............datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sock
datadir是我们安装MySQL时默认指定的存放文件的数据目录,进入文件中删除里面的目录即可。
# cd /var/lib/mysql# rm -rf *