![mysql:mysql.service 的作业失败,因为控制进程退出并显示错误代码](https://linux22.com/image/937993/mysql%EF%BC%9Amysql.service%20%E7%9A%84%E4%BD%9C%E4%B8%9A%E5%A4%B1%E8%B4%A5%EF%BC%8C%E5%9B%A0%E4%B8%BA%E6%8E%A7%E5%88%B6%E8%BF%9B%E7%A8%8B%E9%80%80%E5%87%BA%E5%B9%B6%E6%98%BE%E7%A4%BA%E9%94%99%E8%AF%AF%E4%BB%A3%E7%A0%81.png)
当我跑步时
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.
我在网上搜索并尝试了几乎所有的解决方案,但都无法解决我的问题:
sudo reboot
sudo apt purge mysql-server mysql-client mysql-common
sudo apt purge mysql-client-core-8.0 mysql-server-core-8.0
sudo dpkg -l | grep mysql
# shows empty
sudo rm -rf /etc/mysql/
sudo rm -rf /usr/share/mysql/
sudo apt autopurge
sudo apt autoclean
sudo apt autoremove
sudo apt update && sudo apt upgrade
sudo apt install mysql-server mysql-client
sudo chmod -R u+rwx /etc/mysql/
sudo chown -R mysql.mysql /etc/mysql/
sudo chmod 0640 /var/log/mysql/error.log
# chmod: cannot access '/var/log/mysql/error.log': No such file or directory
sudo chmod 0750 /var/log/mysql
# chmod: cannot access '/var/log/mysql': No such file or directory
sudo chmod 0755 /var
sudo chmod 0775 /var/log
sudo chown mysql:adm /var/log/mysql
# chown: cannot access '/var/log/mysql': No such file or directory
sudo chown mysql:adm /var/log/mysql/error.log
# chown: cannot access '/var/log/mysql/error.log': No such file or directory
sudo chown root:root /var
sudo chown root:syslog /var/log
sudo chown mysql:mysql /var/log/mysql/*
# chown: cannot access '/var/log/mysql/*': No such file or directory
再试一次:
sudo /etc/init.d/mysql start
Starting mysql (via systemctl): mysql.serviceJob for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xe" for details.
failed!
检查
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.2 LTS
Release: 20.04
Codename: focal
df -h --total
Filesystem Size Used Avail Use% Mounted on
udev 948M 0 948M 0% /dev
tmpfs 199M 1.5M 198M 1% /run
/dev/sda2 98G 56G 38G 61% /
tmpfs 994M 0 994M 0% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 994M 0 994M 0% /sys/fs/cgroup
/dev/loop2 33M 33M 0 100% /snap/snapd/11588
/dev/loop3 56M 56M 0 100% /snap/core18/1997
/dev/loop0 56M 56M 0 100% /snap/core18/2066
/dev/loop1 71M 71M 0 100% /snap/lxd/20400
/dev/loop4 33M 33M 0 100% /snap/snapd/11841
/dev/loop5 71M 71M 0 100% /snap/lxd/20450
git 476G 428G 48G 91% /media/sf_git
share 476G 428G 48G 91% /media/sf_share
tmpfs 199M 44K 199M 1% /run/user/1000
/dev/sr0 58M 58M 0 100% /media/ar/VBox_GAs_6.1.12
total 1.1T 913G 135G 88% -
sudo systemctl status mysql.service
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2021-05-26 05:02:47 AEST; 35s ago
Process: 56094 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=1/FAILURE)
May 26 05:02:47 myser systemd[1]: mysql.service: Control process exited, code=exited, status=1/FAILURE
May 26 05:02:47 myser systemd[1]: mysql.service: Failed with result 'exit-code'.
May 26 05:02:47 myser systemd[1]: Failed to start MySQL Community Server.
May 26 05:02:47 myser systemd[1]: mysql.service: Scheduled restart job, restart counter is at 5.
May 26 05:02:47 myser systemd[1]: Stopped MySQL Community Server.
May 26 05:02:47 myser systemd[1]: mysql.service: Start request repeated too quickly.
May 26 05:02:47 myser systemd[1]: mysql.service: Failed with result 'exit-code'.
May 26 05:02:47 myser systemd[1]: Failed to start MySQL Community Server.
sudo journalctl -xe
-- A stop job for unit mysql.service has finished.
--
-- The job identifier is 10868 and the job result is done.
May 26 05:02:47 myser systemd[1]: mysql.service: Start request repeated too quickly.
May 26 05:02:47 myser systemd[1]: mysql.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- The unit mysql.service has entered the 'failed' state with result 'exit-code'.
May 26 05:02:47 myser systemd[1]: Failed to start MySQL Community Server.
-- Subject: A start job for unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- A start job for unit mysql.service has finished with a failure.
--
-- The job identifier is 10868 and the job result is failed.
May 26 05:03:23 myser sudo[56095]: ar : TTY=pts/0 ; PWD=/home/ar/Desktop ; USER=root ; COMMAND=/usr/bin/systemctl status mysql.service
May 26 05:03:23 myser sudo[56095]: pam_unix(sudo:session): session opened for user root by (uid=0)
May 26 05:03:24 myser sudo[56095]: pam_unix(sudo:session): session closed for user root
May 26 05:05:03 myser sudo[56101]: ar : TTY=pts/0 ; PWD=/home/ar/Desktop ; USER=root ; COMMAND=/usr/bin/journalctl -xe
May 26 05:05:03 myser sudo[56101]: pam_unix(sudo:session): session opened for user root by (uid=0)
它没有记录任何内容
sudo tail -30 /var/log/mysql/error.log
tail: cannot open '/var/log/mysql/error.log' for reading: No such file or directory
sudo netstat -tap | grep mysql
(empty result: bad)
whereis mysql
mysql: /usr/bin/mysql /usr/lib/mysql /etc/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
sudo dpkg -l | grep mariadb
(empty: good)
sudo dpkg -l | grep mysql
ii mysql-client 8.0.25-0ubuntu0.20.04.1 all MySQL database client (metapackage depending on the latest version)
ii mysql-client-8.0 8.0.25-0ubuntu0.20.04.1 amd64 MySQL database client binaries
ii mysql-client-core-8.0 8.0.25-0ubuntu0.20.04.1 amd64 MySQL database core client binaries
ii mysql-common 5.8+1.0.5ubuntu2 all MySQL database common files, e.g. /etc/mysql/my.cnf
ii mysql-server 8.0.25-0ubuntu0.20.04.1 all MySQL database server (metapackage depending on the latest version)
ii mysql-server-8.0 8.0.25-0ubuntu0.20.04.1 amd64 MySQL database server binaries and system database setup
ii mysql-server-core-8.0 8.0.25-0ubuntu0.20.04.1 amd64 MySQL database server binaries
还
journalctl -xe | tail -20
-- Support: http://www.ubuntu.com/support
--
-- A stop job for unit mysql.service has finished.
--
-- The job identifier is 11804 and the job result is done.
May 26 05:21:49 myser systemd[1]: mysql.service: Start request repeated too quickly.
May 26 05:21:49 myser systemd[1]: mysql.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- The unit mysql.service has entered the 'failed' state with result 'exit-code'.
May 26 05:21:49 myser systemd[1]: Failed to start MySQL Community Server.
-- Subject: A start job for unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- A start job for unit mysql.service has finished with a failure.
--
-- The job identifier is 11804 and the job result is failed.
尝试配置操作:
sudo gedit /etc/mysql/my.cnf
[mysqld]
innodb_force_recovery = 1
innodb_buffer_pool_size = 20M
然后重试:
sudo service mysql start
Job for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xe" for details.
注意:我曾经有过 mariadb,但是已经将其完全删除。