MySQL mysqld.service 的作业失败请参阅“systemctl status mysqld.service”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42317139/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 22:12:56  来源:igfitidea点击:

Job for mysqld.service failed See "systemctl status mysqld.service"

mysqlamazon-web-services

提问by Nobi

Console says

控制台说

[root@ip-172-31-18-2 mysql]# service mysqld start
Starting mysqld (via systemctl):  Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.

mysqld.service

mysqld.service

[root@ip-172-31-18-2 mysql]# systemctl status mysqld.service
● mysqld.service - SYSV: MySQL database server.
   Loaded: loaded (/etc/rc.d/init.d/mysqld)
   Active: failed (Result: exit-code) since Sat 2017-02-18 20:59:17 IST; 36s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 9925 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=1/FAILURE)

Feb 18 20:59:16 ip-172-31-18-2.ap-southeast-1.compute.internal systemd[1]: Starting SYSV: MySQL database server....
Feb 18 20:59:17 ip-172-31-18-2.ap-southeast-1.compute.internal mysqld[9925]: MySQL Daemon failed to start.
Feb 18 20:59:17 ip-172-31-18-2.ap-southeast-1.compute.internal mysqld[9925]: Starting mysqld:  [FAILED]
Feb 18 20:59:17 ip-172-31-18-2.ap-southeast-1.compute.internal systemd[1]: mysqld.service: control process exited, code=exited status=1
Feb 18 20:59:17 ip-172-31-18-2.ap-southeast-1.compute.internal systemd[1]: Failed to start SYSV: MySQL database server..
Feb 18 20:59:17 ip-172-31-18-2.ap-southeast-1.compute.internal systemd[1]: Unit mysqld.service entered failed state.
Feb 18 20:59:17 ip-172-31-18-2.ap-southeast-1.compute.internal systemd[1]: mysqld.service failed.

What I have tried until now:

到目前为止我尝试过的:

mysqld_safe --defaults-file=/etc/my.cf

chown -R mysql:mysql /var/lib/mysql

/etc/init.d/mysqld start

 /etc/init.d/mysqld stop

systemctl restart systemd-logind

rebooted the server

重新启动了服务器

Still no luck.

仍然没有运气。

my.cnf file

my.cnf 文件

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

回答by Adam Deng

I met this problem today, and fix it with bellowed steps.

我今天遇到了这个问题,并通过以下步骤修复了它。

1, Check the log file /var/log/mysqld.log

1、查看日志文件 /var/log/mysqld.log

tail -f /var/log/mysqld.log

 2017-03-14T07:06:53.374603Z 0 [ERROR] /usr/sbin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 2 - No such file or directory)
 2017-03-14T07:06:53.374614Z 0 [ERROR] Can't start server: can't create PID file: No such file or directory

The log says that there isn't a file or directory /var/run/mysqld/mysqld.pid

日志说没有文件或目录 /var/run/mysqld/mysqld.pid

2, Create the directory /var/run/mysqld

2、创建目录 /var/run/mysqld

mkdir -p /var/run/mysqld/

3, Start the mysqld again service mysqld start, but still fail, check the log again /var/log/mysqld.log

3、再次启动mysqld service mysqld start,还是失败,再次查看日志/var/log/mysqld.log

2017-03-14T07:14:22.967667Z 0 [ERROR] /usr/sbin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 13 - Permission denied)
2017-03-14T07:14:22.967678Z 0 [ERROR] Can't start server: can't create PID file: Permission denied

It saids permission denied.

它说许可被拒绝。

4, Grant the permission to mysql chown mysql.mysql /var/run/mysqld/

4、授予mysql权限 chown mysql.mysql /var/run/mysqld/

5, Restart the mysqld

5、重启mysqld

# service mysqld restart
Restarting mysqld (via systemctl):                         [  OK  ]

回答by CJ-UNIq

These are the steps I took to correct this:

这些是我为纠正此问题而采取的步骤:

Back up your my.cnf file in /etc/mysql and remove or rename it

备份 /etc/mysql 中的 my.cnf 文件并删除或重命名它

sudo mv /etc/mysql/my.cnf /etc/mysql/my.cnf.bak

Remove the folder /etc/mysql/mysql.conf.d/ using

删除文件夹 /etc/mysql/mysql.conf.d/ 使用

sudo rm -r /etc/mysql/mysql.conf.d/

Verify you don't have a my.cnf file stashed somewhere else (I did in my home dir!) or in /etc/alternatives/my.cnf use

确认您没有将 my.cnf 文件藏在其他地方(我在我的主目录中!)或在 /etc/alternatives/my.cnf 中使用

sudo find / -name my.cnf

Now reinstall every thing

现在重新安装所有东西

sudo apt purge mysql-server mysql-server-5.7 mysql-server-core-5.7
sudo apt install mysql-server

In case your syslog shows an error like "mysqld: Can't read dir of '/etc/mysql/conf.d/'" create a symbolic link:

如果您的系统日志显示诸如“mysqld:无法读取 '/etc/mysql/conf.d/' 的目录”之类的错误,请创建一个符号链接:

sudo ln -s /etc/mysql/mysql.conf.d /etc/mysql/conf.d

Then the service should be able to start with sudo service mysql start.

那么服务应该可以用 sudo service mysql start 启动。

I hope it work

我希望它有效

回答by Sergiy Kolodyazhnyy

In my particular case, the error was appearing due to missing /var/log/mysqlwith mysql-serverpackage 5.7.21-1 on Debian-based Linux distro. Having ran straceand sudo /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid( which is what the systemdservice actually runs), it became apparent that the issue was due to this:

在我的特殊情况下,错误出现了,由于缺少/var/log/mysqlmysql-server基于Debian的Linux发行版包装5.7.21-1。运行stracesudo /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid(这是systemd服务实际运行的内容)后,很明显问题是由于以下原因造成的:

2019-01-01T09:09:22.102568Z 0 [ERROR] Could not open file '/var/log/mysql/error.log' for error logging: No such file or directory

I've recently removed contents of several directories in /var/logso it was no surprise. The solution was to create the directory and make it owned by mysqluser as in

我最近删除了几个目录的内容,/var/log所以这并不奇怪。解决方案是创建目录并使其归mysql用户所有,如

$ sudo mkdir /var/log/mysql
$ sudo chown -R mysql:mysql /var/log/mysql

Having done that I've happily logged in via sudo mysql -u rootand greeted with the old and familiar mysql>prompt

完成后,我很高兴地通过以下方式登录sudo mysql -u root并看到了旧的和熟悉的mysql>提示

回答by juanitourquiza

I had the same error, the problem was because I no longer had disk space. to check the space run this:

我有同样的错误,问题是因为我不再有磁盘空间。检查空间运行这个:

$ df -h

disk space

磁盘空间

Then delete some files that you didn't need.

然后删除一些你不需要的文件。

After this commands:

在此命令之后:

service mysql start
systemctl status mysql.service
mysql -u root -p

After entering with the root password verify that the mysql service was active

使用 root 密码输入后验证 mysql 服务是否处于活动状态

回答by Yemi Gatyee

This amazingly worked.

这非常有效。

/etc/init.d/mysql stop
service mysql stop
killall -KILL mysql mysqld_safe mysqld
/etc/init.d/mysql start
service mysql start

回答by bobo

try

尝试

sudo chown mysql:mysql -R /var/lib/mysql

then start your mysql service

然后启动你的mysql服务

systemctl start mysqld

回答by rajat saha

Had the same problem. Solved as given below. Use command :

有同样的问题。解决如下。使用命令:

sudo tail -f /var/log/messages|grep -i mysql

to check if SELinux policy is causing the issue. If so, first check if SELinux policy is enabled using command #sestatus. If it shows enabled, then disable it. To disable:

检查 SELinux 策略是否导致了问题。如果是这样,首先使用命令检查是否启用了 SELinux 策略#sestatus。如果显示已启用,则禁用它。要禁用:

  1. # vi /etc/sysconfig/selinux
  2. change 'SELINUX=enforcing' to 'SELINUX=disabled'
  3. restart linux
  4. check with sestatusand it should show "disabled"
  1. # vi /etc/sysconfig/selinux
  2. 将“SELINUX=enforcing”更改为“SELINUX=disabled”
  3. 重启 linux
  4. 检查sestatus它应该显示“已禁用”

Uninstall and reinstall mysql. It should be working.

卸载并重新安装mysql。它应该工作。