【问题标题】:Job for mysqld.service failed See "systemctl status mysqld.service"mysqld.service 的作业失败 请参阅“systemctl status mysqld.service”
【发布时间】:2017-07-08 02:43:37
【问题描述】:

控制台说

[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 an 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 a 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

【问题讨论】:

标签: mysql linux database amazon-web-services


【解决方案1】:

这非常有效。

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

【讨论】:

  • 这不起作用。 failed!roo:~# /etc/init.d/mysql start root@thyroo:~# mysql (via systemctl): mysql.service 的 mysql.serviceJob 失败,因为控制进程以错误代码退出。详见“systemctl status mysql.service”和“journalctl -xe”。
  • mysql.service 的作业失败,因为控制进程以错误代码退出。
  • 这真的很有帮助。谢谢
【解决方案2】:

我今天遇到了这个问题,用下面的步骤解决它。

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、再次启动mysqldservice 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  ]

【讨论】:

  • 感谢您指出日志文件sudo cat /var/log/mysqld.log。在那里我找到了我个人问题的清晰描述(磁盘配额)。
  • 谢谢。我必须检查 MySQL 错误日志文件:tail -f /var/log/mysql/error.log。就我而言,我有一个 docker 容器在与 MySQL 相同的进程上运行。我不得不停止 docker 容器进程。
【解决方案3】:

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

$ df -h

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

在此命令之后:

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

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

【讨论】:

  • 这正是我的流浪机器发生的事情,所以我撞了磁盘。
  • 感谢上帝,我向下滚动查看您的答案。正是问题所在。
【解决方案4】:

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

在 /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: Can't read dir of '/etc/mysql/conf.d/'”之类的错误,请创建符号链接:

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

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

希望能成功

【讨论】:

  • 这也会清除数据吗?
  • @hocuspocus31 是的,它会删除mysql数据库和整个数据。
【解决方案5】:

在我的特定情况下,由于在基于 Debian 的 Linux 发行版上缺少 /var/log/mysqlmysql-server 包 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

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

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

完成此操作后,我很高兴通过 sudo mysql -u root 登录并看到旧的和熟悉的 mysql> 提示符

【讨论】:

  • 这对我来说是个问题!忘了我已经将日志更改为由 root 拥有...非常感谢!
  • @nights 很高兴我能帮上忙 :)
  • @SergiyKolodyazhnyy 你不明白上帝是如何使用这个答案来拯救我今天免于双重尴尬的。谢谢。非常感谢。
  • 谢谢,我使用了 Stacer 系统清理器并删除了我的应用程序日志 :(apache2 文件夹也需要这个
  • 非常感谢,这是我的问题,我访问 MySQL 的权限被拒绝,这是一个非常有帮助的答案。
【解决方案6】:

试试

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

然后启动你的mysql服务

systemctl start mysqld

【讨论】:

  • mysql.service 的作业失败,因为控制进程以错误代码退出。
【解决方案7】:

问题在于“/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/

【讨论】:

    【解决方案8】:

    如果您的问题没有解决,您可以尝试检查更多问题。

    可能是 mysql 崩溃,像这样:

    您可以检查登录

    sudo cat /var/log/mysql/error.log

    或者你检查

    sudo ls /var/crash

    【讨论】:

      【解决方案9】:

      我也遇到了同样的问题。

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

      mysql: [警告] 在命令行界面使用密码即可 不安全。 ERROR 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
      

      问题终于解决了。

      【讨论】:

        【解决方案10】:
        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 的状态。如果权限已更改,则服务无法将任何内容写入日志文件。如果发生这种情况,它将停止运行服务

        【讨论】:

          【解决方案11】:

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

          【讨论】:

            【解决方案12】:

            您可以清除所有与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 除外),请将它们添加到您的列表中

            【讨论】:

              【解决方案13】:

              备份您的配置或数据并重新安装 mysql

              sudo apt remove --purge mysql-server
              sudo apt purge mysql-server
              sudo apt autoremove
              sudo apt autoclean
              sudo apt remove dbconfig-mysql
              
              
              sudo apt-get remove --purge mysql* -y
              sudo apt-get autoremove -y
              sudo apt-get autoclean
              

              然后重新安装。

              这在这里有效。

              【讨论】:

                【解决方案14】:

                我有相同的“systemctl status mysql.service”和“journalctl -xe”了解详细信息。错误。 经过反复卸载和安装根本不起作用。 但是这个效果很好>https://linuxtut.com/en/5a5b0f46620ae1b27b10/

                您只需要从 my.cnf 文件中删除除 [mysqld] 之外的所有内容并启动服务器。这真的有效。但在这种情况下,您可能没有 root 的密码,请跳过授权表并以安全模式重新启动服务器并使用 mysql 和 更新 mysql.user set authentication_string=null where user='root' 然后可以更改由 'your_$$new_99pwd#' 标识的用户 'root'@'localhost'; 然后登录到安全模式,然后你就可以创建新用户了。

                【讨论】:

                  【解决方案15】:

                  遇到了同样的问题。解决如下。 使用命令:

                  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。它应该可以工作。

                  【讨论】:

                  • 这就像“我时不时忘记密码。我该怎么办?” – “从您的帐户中删除密码,您会没事的。”
                  猜你喜欢
                  • 2021-08-03
                  • 2018-11-14
                  • 2015-07-30
                  • 2016-09-04
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  相关资源
                  最近更新 更多