MySQL 8 和 MySQL RHEL 7 - 自动启动服务失败

发布于 2025-01-14 00:14:24 字数 4622 浏览 4 评论 0原文

我正在尝试在重新启动时正常关闭并启动 MySQL 8 安装。 我已使用以下命令通过 systemctl 启用了该服务。

systemctl enable rh-mysql80-mysqld.service

重新启动后,我检查状态

root@localhost > systemctl status rh-mysql80-mysqld.service
● rh-mysql80-mysqld.service - MySQL 8.0 database server
   Loaded: loaded (/usr/lib/systemd/system/rh-mysql80-mysqld.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Fri 2022-03-11 12:18:24 PST; 16min ago
  Process: 1635 ExecStopPost=/usr/bin/scl enable $RH_MYSQL80_SCLS_ENABLED -- /opt/rh/rh-mysql80/root/usr/libexec/mysql-wait-stop (code=exited, status=0/SUCCESS)
  Process: 1242 ExecStart=/opt/rh/rh-mysql80/root/usr/libexec/mysqld-scl-helper enable $RH_MYSQL80_SCLS_ENABLED -- /opt/rh/rh-mysql80/root/usr/libexec/mysqld --basedir=/opt/rh/rh-mysql80/root/usr (code=exited, status=1/FAILURE)
  Process: 1165 ExecStartPre=/usr/bin/scl enable $RH_MYSQL80_SCLS_ENABLED -- /opt/rh/rh-mysql80/root/usr/libexec/mysql-prepare-db-dir %n (code=exited, status=0/SUCCESS)
  Process: 1098 ExecStartPre=/usr/bin/scl enable $RH_MYSQL80_SCLS_ENABLED -- /opt/rh/rh-mysql80/root/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
  Process: 1059 ExecStartPre=/usr/bin/scl enable $RH_MYSQL80_SCLS_ENABLED -- /usr/bin/scl_enabled rh-mysql80 (code=exited, status=0/SUCCESS)
 Main PID: 1242 (code=exited, status=1/FAILURE)
   Status: "Server startup in progress"

,我在 mysqld.log 中看到此

   /var/log/mysql/mysqld.log
   2022-03-11T20:18:24.356194Z 0 [ERROR] [MY-011811] [Server] Can't start server: can't check PID filepath: No such file or directory

  

信息。执行以下命令后,我能够手动启动该服务

[root@localhost ~]# sudo mkdir -p /var/run/rh-mysql80-mysqld/
[root@localhost ~]# sudo chown mysql.mysql /var/run/rh-mysql80-mysqld/


[root@localhost ~]# systemctl status rh-mysql80-mysqld.service
● rh-mysql80-mysqld.service - MySQL 8.0 database server
   Loaded: loaded (/usr/lib/systemd/system/rh-mysql80-mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2022-03-11 12:58:16 PST; 58s ago
  Process: 1635 ExecStopPost=/usr/bin/scl enable $RH_MYSQL80_SCLS_ENABLED -- /opt/rh/rh-mysql80/root/usr/libexec/mysql-wait-stop (code=exited, status=0/SUCCESS)
  Process: 14780 ExecStartPost=/usr/bin/scl enable $RH_MYSQL80_SCLS_ENABLED -- /opt/rh/rh-mysql80/root/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
  Process: 14678 ExecStartPre=/usr/bin/scl enable $RH_MYSQL80_SCLS_ENABLED -- /opt/rh/rh-mysql80/root/usr/libexec/mysql-prepare-db-dir %n (code=exited, status=0/SUCCESS)
  Process: 14647 ExecStartPre=/usr/bin/scl enable $RH_MYSQL80_SCLS_ENABLED -- /opt/rh/rh-mysql80/root/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
  Process: 14641 ExecStartPre=/usr/bin/scl enable $RH_MYSQL80_SCLS_ENABLED -- /usr/bin/scl_enabled rh-mysql80 (code=exited, status=0/SUCCESS)
 Main PID: 14721 (mysqld)
   Status: "Server is operational"
   CGroup: /system.slice/rh-mysql80-mysqld.service
           └─14721 /opt/rh/rh-mysql80/root/usr/libexec/mysqld --basedir=/opt/rh/rh-mysql80/root/usr

Mar 11 12:58:15 localhost systemd[1]: Starting MySQL 8.0 database server...
Mar 11 12:58:15 localhost scl[14647]: Socket file /var/lib/mysql/mysql.sock exists.
Mar 11 12:58:15 localhost scl[14647]: No process is using /var/lib/mysql/mysql.sock, which means it is a garbage, so it will be removed automatically.
Mar 11 12:58:16 localhost systemd[1]: Started MySQL 8.0 database server.

谁能告诉我需要做什么,以便该服务可以在重新启动时成功启动而无需手动干预?

OS Linux 3.10.0-1160.59.1.el7.x86_64 #1 SMP Wed Feb 16 12:17:35 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

更新: 我想我找到了我的问题。

在访问谷歌大学时,我发现其他人通过创建一个服务来在 /var/run 中创建丢失的目录,“修复”了相同或类似的问题。我尝试了一个小时左右,但没有成功。

然后我偶然发现了一份 MySQL 错误报告,该报告让我开始搜索以找到该文件。

-rw-r--r-- 1 root root 44 Sep 16 05:05 /usr/lib/tmpfiles.d/rh-mysql80-mysqld.conf

该文件的内容

d /run/rh-mysql80-mysqld 0755 mysql mysql -

如果该文件存在,为什么它不起作用。我查看了 /varlog/messages 并发现:

Mar 11 15:43:03 systemd-tmpfiles: [/usr/lib/tmpfiles.d/rh-mysql80-mysqld.conf:1] Unknown group 'mysql'.
Mar 11 15:43:03 systemd: systemd-tmpfiles-setup.service: main process exited, code=exited, status=1/FAILURE
Mar 11 15:43:03 systemd: Unit systemd-tmpfiles-setup.service entered failed state.
Mar 11 15:43:03 systemd: systemd-tmpfiles-setup.service failed.

“mysql”不在 /etc/group 文件中(尽管 groupadd 命令说它已经存在),所以我手动添加了它。

做了这个改变,重新启动......然后BOOM!!......Mysql自动启动!

I'm trying to shutdown and startup a MySQL 8 installation gracefully on reboot.
I've enable the service with systemctl with the following command.

systemctl enable rh-mysql80-mysqld.service

After rebooting I check the status

root@localhost > systemctl status rh-mysql80-mysqld.service
● rh-mysql80-mysqld.service - MySQL 8.0 database server
   Loaded: loaded (/usr/lib/systemd/system/rh-mysql80-mysqld.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Fri 2022-03-11 12:18:24 PST; 16min ago
  Process: 1635 ExecStopPost=/usr/bin/scl enable $RH_MYSQL80_SCLS_ENABLED -- /opt/rh/rh-mysql80/root/usr/libexec/mysql-wait-stop (code=exited, status=0/SUCCESS)
  Process: 1242 ExecStart=/opt/rh/rh-mysql80/root/usr/libexec/mysqld-scl-helper enable $RH_MYSQL80_SCLS_ENABLED -- /opt/rh/rh-mysql80/root/usr/libexec/mysqld --basedir=/opt/rh/rh-mysql80/root/usr (code=exited, status=1/FAILURE)
  Process: 1165 ExecStartPre=/usr/bin/scl enable $RH_MYSQL80_SCLS_ENABLED -- /opt/rh/rh-mysql80/root/usr/libexec/mysql-prepare-db-dir %n (code=exited, status=0/SUCCESS)
  Process: 1098 ExecStartPre=/usr/bin/scl enable $RH_MYSQL80_SCLS_ENABLED -- /opt/rh/rh-mysql80/root/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
  Process: 1059 ExecStartPre=/usr/bin/scl enable $RH_MYSQL80_SCLS_ENABLED -- /usr/bin/scl_enabled rh-mysql80 (code=exited, status=0/SUCCESS)
 Main PID: 1242 (code=exited, status=1/FAILURE)
   Status: "Server startup in progress"

I see this in the mysqld.log

   /var/log/mysql/mysqld.log
   2022-03-11T20:18:24.356194Z 0 [ERROR] [MY-011811] [Server] Can't start server: can't check PID filepath: No such file or directory

  

After executing the following commands I am able to manually start the service

[root@localhost ~]# sudo mkdir -p /var/run/rh-mysql80-mysqld/
[root@localhost ~]# sudo chown mysql.mysql /var/run/rh-mysql80-mysqld/


[root@localhost ~]# systemctl status rh-mysql80-mysqld.service
● rh-mysql80-mysqld.service - MySQL 8.0 database server
   Loaded: loaded (/usr/lib/systemd/system/rh-mysql80-mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2022-03-11 12:58:16 PST; 58s ago
  Process: 1635 ExecStopPost=/usr/bin/scl enable $RH_MYSQL80_SCLS_ENABLED -- /opt/rh/rh-mysql80/root/usr/libexec/mysql-wait-stop (code=exited, status=0/SUCCESS)
  Process: 14780 ExecStartPost=/usr/bin/scl enable $RH_MYSQL80_SCLS_ENABLED -- /opt/rh/rh-mysql80/root/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
  Process: 14678 ExecStartPre=/usr/bin/scl enable $RH_MYSQL80_SCLS_ENABLED -- /opt/rh/rh-mysql80/root/usr/libexec/mysql-prepare-db-dir %n (code=exited, status=0/SUCCESS)
  Process: 14647 ExecStartPre=/usr/bin/scl enable $RH_MYSQL80_SCLS_ENABLED -- /opt/rh/rh-mysql80/root/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
  Process: 14641 ExecStartPre=/usr/bin/scl enable $RH_MYSQL80_SCLS_ENABLED -- /usr/bin/scl_enabled rh-mysql80 (code=exited, status=0/SUCCESS)
 Main PID: 14721 (mysqld)
   Status: "Server is operational"
   CGroup: /system.slice/rh-mysql80-mysqld.service
           └─14721 /opt/rh/rh-mysql80/root/usr/libexec/mysqld --basedir=/opt/rh/rh-mysql80/root/usr

Mar 11 12:58:15 localhost systemd[1]: Starting MySQL 8.0 database server...
Mar 11 12:58:15 localhost scl[14647]: Socket file /var/lib/mysql/mysql.sock exists.
Mar 11 12:58:15 localhost scl[14647]: No process is using /var/lib/mysql/mysql.sock, which means it is a garbage, so it will be removed automatically.
Mar 11 12:58:16 localhost systemd[1]: Started MySQL 8.0 database server.

Can anyone tell me what needs to be done so that the service can successfully start on reboot without the manual intervention ?

OS Linux 3.10.0-1160.59.1.el7.x86_64 #1 SMP Wed Feb 16 12:17:35 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

UPDATE:
I think I found my problem.

While visiting google university I found other people had "fixed" the same or similar problem by creating a service to create the missing directory in /var/run. I tried this unsuccessfully for an hour or so.

I then stumbled across a MySQL bug report which sent me on a search to locate this file.

-rw-r--r-- 1 root root 44 Sep 16 05:05 /usr/lib/tmpfiles.d/rh-mysql80-mysqld.conf

The contents of this file

d /run/rh-mysql80-mysqld 0755 mysql mysql -

If this file exists, why is it not working. I took a look in /varlog/messages and found this:

Mar 11 15:43:03 systemd-tmpfiles: [/usr/lib/tmpfiles.d/rh-mysql80-mysqld.conf:1] Unknown group 'mysql'.
Mar 11 15:43:03 systemd: systemd-tmpfiles-setup.service: main process exited, code=exited, status=1/FAILURE
Mar 11 15:43:03 systemd: Unit systemd-tmpfiles-setup.service entered failed state.
Mar 11 15:43:03 systemd: systemd-tmpfiles-setup.service failed.

"mysql" wasnt in the /etc/group file (despite the groupadd command saying that it already existed) so I manually added it.

Made this change, rebooted.... and BOOM!!....Mysql started automatically!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文