如何永久修复:mysql.service作业失败,因为控制进程以错误代码退出

10

我正在使用 Ubuntu 18.04 和 MySQL Server - 8.0.18。

今天突然间 MySQL 无法启动了。

使用命令 sudo service mysql status 会显示:

sudo service mysql status
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sat 2019-11-02 17:05:23 -05; 1min 44s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 1659 ExecStart=/usr/sbin/mysqld (code=exited, status=2)
  Process: 1620 ExecStartPre=/usr/share/mysql-8.0/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 1659 (code=exited, status=2)
   Status: "Server startup in progress"

Nov 02 17:05:22 asus2016-vb01 systemd[1]: mysql.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Nov 02 17:05:22 asus2016-vb01 systemd[1]: mysql.service: Failed with result 'exit-code'.
Nov 02 17:05:22 asus2016-vb01 systemd[1]: Failed to start MySQL Community Server.
Nov 02 17:05:23 asus2016-vb01 systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Nov 02 17:05:23 asus2016-vb01 systemd[1]: mysql.service: Scheduled restart job, restart counter is at 9.
Nov 02 17:05:23 asus2016-vb01 systemd[1]: Stopped MySQL Community Server.
Nov 02 17:05:23 asus2016-vb01 systemd[1]: mysql.service: Start request repeated too quickly.
Nov 02 17:05:23 asus2016-vb01 systemd[1]: mysql.service: Failed with result 'exit-code'.
Nov 02 17:05:23 asus2016-vb01 systemd[1]: Failed to start MySQL Community Server.

使用 sudo service mysql restart 命令出现以下情况:

sudo service mysql restart
Job for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xe" for details.

执行以下两个建议的命令:

  • systemctl status mysql.service
  • journalctl -xe

因此:sudo systemctl status mysql.service

sudo systemctl status mysql.service
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sat 2019-11-02 17:08:21 -05; 38s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 2633 ExecStart=/usr/sbin/mysqld (code=exited, status=2)
  Process: 2594 ExecStartPre=/usr/share/mysql-8.0/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 2633 (code=exited, status=2)
   Status: "Server startup in progress"

Nov 02 17:08:20 asus2016-vb01 systemd[1]: mysql.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Nov 02 17:08:20 asus2016-vb01 systemd[1]: mysql.service: Failed with result 'exit-code'.
Nov 02 17:08:20 asus2016-vb01 systemd[1]: Failed to start MySQL Community Server.
Nov 02 17:08:21 asus2016-vb01 systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Nov 02 17:08:21 asus2016-vb01 systemd[1]: mysql.service: Scheduled restart job, restart counter is at 5.
Nov 02 17:08:21 asus2016-vb01 systemd[1]: Stopped MySQL Community Server.
Nov 02 17:08:21 asus2016-vb01 systemd[1]: mysql.service: Start request repeated too quickly.
Nov 02 17:08:21 asus2016-vb01 systemd[1]: mysql.service: Failed with result 'exit-code'.
Nov 02 17:08:21 asus2016-vb01 systemd[1]: Failed to start MySQL Community Server.

使用journalctl -xe命令。

-- Unit mysql.service has begun starting up.
Nov 02 17:08:20 asus2016-vb01 audit[2632]: AVC apparmor="STATUS" operation="profile_replace" info="same as current profile, skipping" profile="unconfined" name="/usr/sbin/mysqld" pid=2632 comm="apparmor_p
Nov 02 17:08:20 asus2016-vb01 audit[2633]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/etc/ssl/openssl.cnf" pid=2633 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=122
Nov 02 17:08:20 asus2016-vb01 audit[2633]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/2633/task/2634/mem" pid=2633 comm="mysqld" requested_mask="r" denied_mask="r" fsuid
Nov 02 17:08:20 asus2016-vb01 systemd[1]: mysql.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Nov 02 17:08:20 asus2016-vb01 systemd[1]: mysql.service: Failed with result 'exit-code'.
Nov 02 17:08:20 asus2016-vb01 systemd[1]: Failed to start MySQL Community Server.
-- Subject: Unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Unit mysql.service has failed.
-- 
-- The result is RESULT.
Nov 02 17:08:21 asus2016-vb01 systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Nov 02 17:08:21 asus2016-vb01 systemd[1]: mysql.service: Scheduled restart job, restart counter is at 5.
-- Subject: Automatic restarting of a unit has been scheduled

我按照这篇帖子的解决方案进行操作:

我使用了innodb_force_recovery = 10(十),因为1和2都不起作用。

因此,通过sudo systemctl start mysql命令可以启动服务器。我可以看到所有的数据和保存的用户。

现在,通过sudo systemctl status mysql命令,我得到:

sudo systemctl status mysql
 mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2019-11-02 17:26:48 -05; 11s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 2769 ExecStartPre=/usr/share/mysql-8.0/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 2808 (mysqld)
   Status: "Server is operational"
    Tasks: 19 (limit: 4617)
   CGroup: /system.slice/mysql.service
           └─2808 /usr/sbin/mysqld

Nov 02 17:26:47 asus2016-vb01 systemd[1]: Starting MySQL Community Server...
Nov 02 17:26:48 asus2016-vb01 systemd[1]: Started MySQL Community Server.

在这一点上,这篇文章可能没有意义,但如果我执行Alpha或Beta步骤:

Alpha (steps): 
sudo systemctl stop mysql
remove innodb_force_recovery = 10
sudo systemctl start mysql         

Beta (steps):
restart the PC, 
(I can confirm `MySQL` was started), 
remove innodb_force_recovery = 10
restart the PC

同样的问题再次出现。

因此,现在强制保持 innodb_force_recovery = 10 是必需的,否则它会返回到相同的问题。

警告:

根据:

正确的范围是从 1 到 6,我认为 10 被“解释”为最大值(6)

有没有一种方法可以配置什么东西并删除 innodb_force_recovery?以恢复到正常或旧的配置,在那里所有工作都很好(没有 innodb_force_recovery

注意/var/log/mysql/error.log 的最终内容为

The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
information that should help you find out what is causing the crash.
2019-11-02T23:24:37.346875Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.18) starting as process 1668
2019-11-02T23:24:37.804662Z 1 [ERROR] [MY-012671] [InnoDB] Encryption algorithm support missing: N
2019-11-02T23:24:37.804783Z 1 [ERROR] [MY-013183] [InnoDB] Assertion failure: log0recv.cc:3563:err == DB_SUCCESS thread 139850038036224
InnoDB: We intentionally generate a memory trap.
InnoDB: Submit a detailed bug report to http://bugs.mysql.com.
InnoDB: If you get repeated assertion failures or crashes, even
InnoDB: immediately after the mysqld startup, there may be
InnoDB: corruption in the InnoDB tablespace. Please refer to
InnoDB: http://dev.mysql.com/doc/refman/8.0/en/forcing-innodb-recovery.html
InnoDB: about forcing recovery.
23:24:37 UTC - mysqld got signal 6 ;
Most likely, you have hit a bug, but this error can also be caused by malfunctioning hardware.
Thread pointer: 0x555c74a041c0
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 7f315fd6bce0 thread_stack 0x46000
/usr/sbin/mysqld(my_print_stacktrace(unsigned char const*, unsigned long)+0x3d) [0x555c72ab2edd]
/usr/sbin/mysqld(handle_fatal_signal+0x303) [0x555c71b5bc63]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x12890) [0x7f317319a890]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0xc7) [0x7f31712d3e97]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x141) [0x7f31712d5801]
/usr/sbin/mysqld(ut_dbg_assertion_failed(char const*, char const*, unsigned long)+0x2ec) [0x555c72d6015c]
/usr/sbin/mysqld(+0x2074038) [0x555c72c1d038]
/usr/sbin/mysqld(recv_recovery_from_checkpoint_start(log_t&, unsigned long)+0x660) [0x555c72c26e40]
/usr/sbin/mysqld(srv_start(bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)+0x1741) [0x555c72d0e701]
/usr/sbin/mysqld(+0x1fe3f25) [0x555c72b8cf25]
/usr/sbin/mysqld(dd::bootstrap::DDSE_dict_init(THD*, dict_init_mode_t, unsigned int)+0x9f) [0x555c72868f5f]
/usr/sbin/mysqld(dd::upgrade_57::do_pre_checks_and_initialize_dd(THD*)+0x5b4) [0x555c72a7d8f4]
/usr/sbin/mysqld(+0x1076dc5) [0x555c71c1fdc5]
/usr/sbin/mysqld(+0x24182b9) [0x555c72fc12b9]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x76db) [0x7f317318f6db]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x3f) [0x7f31713b688f]

Trying to get some variables.
Some pointers may be invalid and cause the dump to abort.
Query (0): is an invalid pointer
Connection ID (thread ID): 1
Status: NOT_KILLED

The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
information that should help you find out what is causing the crash.

我正在使用VirtualBox - Ubuntu是作为客户端。它已经工作了超过3个月,现在突然出现了这种情况。


你最近备份了吗?你只使用备份进行测试了吗?虚拟盒子是一个文件,文件系统中不时会发生错误,此外,您还应该检查硬盘驱动器是否存在错误(S.m.a.r.t和文件系统检查)。 - nbk
1
@nbk 我现在记得了,我遇到这种情况是因为我失去了互联网连接,然后重新启动了Ubuntu。似乎在幕后MySQL受到了影响。 - Manuel Jordan
每当mysql升级/更新失败时,我都会遇到这个问题。我已经解决过几次了,但这一次卡住了。 - aks
我从未解决过这个问题...可悲的是必须重新安装MySQL,并禁用自动启动功能。 - Manuel Jordan
1个回答

5

我也遇到过相同的问题,这里有一些帮助。我的服务器在AWS上运行,将实例降级到内存较少的服务器(512MB),似乎Mysql需要最少1GB的内存,请确认您拥有足够的RAM内存。


我的情况是Ubuntu启动过程失败了,有些东西被损坏了。我的解决方案是卸载并重新安装MySQL,当然所有数据都丢失了。但这只是开发环境,不是生产环境。教训是在Ubuntu中禁用了MySQL的自动启动。 - Manuel Jordan
在我的情况下,问题是磁盘已满。删除一些不必要的文件显然有所帮助。 - Jakub Matěna
AWS是一个糟糕的服务提供商,不建议使用它,数字海洋没有问题,AWS制造这些问题只是为了赚更多的钱。 - Mahmoud Magdy

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接