mysqld.service的作业失败请参阅" systemctl status mysqld.service"

时间:2017-02-18 15:34:16

标签: mysql amazon-web-services

控制台说

[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

[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.

到目前为止我一直在尝试:

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

重新启动服务器

仍然没有运气。

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

12 个答案:

答案 0 :(得分:11)

这很了不起。

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

答案 1 :(得分:5)

我今天遇到了这个问题,并用吼叫的步骤修复它。

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

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

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

mkdir -p /var/run/mysqld/

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

它说许可被否定了。

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

5,重启mysqld

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

答案 2 :(得分:1)

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

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

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

使用以下方式删除文件夹/etc/mysql/mysql.conf.d /

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

验证您没有将my.cnf文件保存在其他地方(我在家庭目录中!)或在/etc/alternatives/my.cnf中使用

sudo find / -name my.cnf

现在重新安装所有东西

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

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

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

然后该服务应该能够以sudo服务mysql start启动。

我希望它能起作用

答案 3 :(得分:1)

尝试

About

然后启动您的mysql服务

GoogleMap

答案 4 :(得分:0)

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

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

检查SELinux策略是否引起了该问题。如果是这样,请首先使用命令#sestatus检查是否启用了SELinux策略。如果显示已启用,则将其禁用。 要禁用:

  1. # vi /etc/sysconfig/selinux
  2. 将'SELINUX = enforcing'更改为'SELINUX = disabled'
  3. 重新启动linux
  4. 检查sestatus,它应显示“已禁用”

卸载并重新安装mysql。应该可以。

答案 5 :(得分:0)

在我的特殊情况下,由于基于Debian的Linux发行版上的/var/log/mysql软件包mysql-server缺少strace软件包而出现了错误。运行了sudo /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pidsystemd(这实际上是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 服务的运行方式)之后,问题显然是由于以下原因造成的:

/var/log

我最近删除了mysql中几个目录的内容,这不足为奇。解决方案是创建目录,并使其$ sudo mkdir /var/log/mysql $ sudo chown -R mysql:mysql /var/log/mysql 用户拥有,如

sudo mysql -u root

已经通过mysql>愉快地登录并迎接了熟悉的旧getRange提示

答案 6 :(得分:0)

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

$ df -h

disk space

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

此命令后:

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

使用root密码输入后,确认mysql服务处于活动状态

答案 7 :(得分:0)

我也面临着同样的问题。

root@*******:/root >mysql -uroot -password

mysql:[警告]在命令行界面上使用密码可以 不安全。错误2002(HY000):无法连接到本地MySQL服务器 通过套接字'/var/lib/mysql/mysql.sock'(2)

I found ROOT FS was also full and then I killed below lock session . 
root@**********:/var/lib/mysql >ls -ltr
total 0
-rw------- 1 mysql mysql 0 Sep  9 06:41 mysql.sock.lock

最终问题已解决。

答案 8 :(得分:0)

  1. 打开my.cnf并复制log-error路径

  2. 然后使用
    检查复制的日志文件的权限 $ ls -l /var/log/mysql.log

  3. 如果日志文件的权限可能从mysql:mysql更改,请将文件权限更改为
    $ chown -R mysql:mysql /var/log/mysql.log

  4. 然后重新启动mysql服务器
    $ service mysql restart || systemctl restart mysqld

注意:这种由权限问题形成的错误。所有的mysql服务启动命令都使用日志文件来写入mysql的状态。如果权限已更改,则该服务不能被写入日志文件中。如果发生这种情况,它将停止运行服务

答案 9 :(得分:0)

问题出在“ /etc/mysql/my.cnf”。此文件必须由您安装的其他库修改。原来是这样的:

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation.  The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

#
# The MySQL  Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#

!includedir /etc/mysql/conf.d/
    
!includedir /etc/mysql/mysql.conf.d/

答案 10 :(得分:0)

删除/etc/mysql/my.cnf“secure_file_priv”的任何命令并重启mysql。 如果要使用 mysql 中的文件,请将这些文件复制到主文件夹。 主文件夹是这样获取的:SHOW VARIABLES LIKE "secure_file_priv";

答案 11 :(得分:0)

您可以使用以下命令清除所有与 mysql 相关的软件包并重新安装它们:

PACKAGES="mysql-server mysql-community-server mysql-community-server-core mysql-client mysql-client mysql-community-client mysql-community-client-core  mysql-common mysql-community-client-plugins php-mysql"
apt purge $PACKAGES
echo "any remaining installed packages:"
dpkg -l|grep ii|grep mysql
apt install --reinstall mysql-common
apt install $PACKAGES

如果还有剩余的软件包(除了 mysql-core),请将它们添加到您的列表中