ERROR 2002(HY000):无法通过socket'/var/run/mysqld/mysqld.sock'连接到本地MySQL服务器(2)发生

时间:2017-08-24 13:12:52

标签: mysql ubuntu-16.04

启动MySql服务器时,我不断收到此错误。 提到的sock文件的路径是 /var/run/mysqld/mysqld.sock 。 我试图以其他方式找到它但文件丢失了。

运行 systemctl status mysql.service 后输出为

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: activating (start-post) (Result: exit-code) since Thu 2017-08-24 12:58:44 UTC; 26s ago
  Process: 19985 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
  Process: 19976 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 19985 (code=exited, status=1/FAILURE);         : 19986 (mysql-systemd-s)
    Tasks: 2
   Memory: 328.0K
      CPU: 262ms
   CGroup: /system.slice/mysql.service
           └─control
             ├─19986 /bin/bash /usr/share/mysql/mysql-systemd-start post
             └─20068 sleep 1

Aug 24 12:58:44 ip-172-31-25-190 systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Aug 24 12:58:44 ip-172-31-25-190 systemd[1]: Stopped MySQL Community Server.
Aug 24 12:58:44 ip-172-31-25-190 systemd[1]: Starting MySQL Community Server...
Aug 24 12:58:46 ip-172-31-25-190 systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE

在输出生成后运行 journalctl -xe

Aug 24 12:58:44 ip-172-31-25-190 systemd[1]: Starting MySQL Community Server...
-- Subject: Unit mysql.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has begun starting up.
Aug 24 12:58:44 ip-172-31-25-190 kernel: audit: type=1400 audit(1503579524.748:818): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/19985/sta
Aug 24 12:58:44 ip-172-31-25-190 kernel: audit: type=1400 audit(1503579524.748:819): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/sy
Aug 24 12:58:44 ip-172-31-25-190 kernel: audit: type=1400 audit(1503579524.748:820): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/19985/sta
Aug 24 12:58:44 ip-172-31-25-190 audit[19985]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/19985/status" pid=19985 comm="mysqld" reque
Aug 24 12:58:44 ip-172-31-25-190 audit[19985]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/system/node/" pid=19985 comm="mysqld
Aug 24 12:58:44 ip-172-31-25-190 audit[19985]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/19985/status" pid=19985 comm="mysqld" reque
Aug 24 12:58:46 ip-172-31-25-190 systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE
Aug 24 12:59:14 ip-172-31-25-190 systemd[1]: Failed to start MySQL Community Server.
-- Subject: Unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has failed.
--
-- The result is failed.
Aug 24 12:59:14 ip-172-31-25-190 systemd[1]: mysql.service: Unit entered failed state.
Aug 24 12:59:14 ip-172-31-25-190 systemd[1]: mysql.service: Failed with result 'exit-code'.
Aug 24 12:59:14 ip-172-31-25-190 systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Aug 24 12:59:14 ip-172-31-25-190 systemd[1]: Stopped MySQL Community Server.
-- Subject: Unit mysql.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has finished shutting down.
Aug 24 12:59:14 ip-172-31-25-190 systemd[1]: Starting MySQL Community Server...
-- Subject: Unit mysql.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has begun starting up.
Aug 24 12:59:15 ip-172-31-25-190 kernel: audit: type=1400 audit(1503579555.004:821): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/20089/sta
Aug 24 12:59:15 ip-172-31-25-190 audit[20089]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/20089/status" pid=20089 comm="mysqld" reque
Aug 24 12:59:15 ip-172-31-25-190 audit[20089]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/system/node/" pid=20089 comm="mysqld
Aug 24 12:59:15 ip-172-31-25-190 audit[20089]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/20089/status" pid=20089 comm="mysqld" reque
Aug 24 12:59:15 ip-172-31-25-190 kernel: audit: type=1400 audit(1503579555.012:822): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/sy
Aug 24 12:59:15 ip-172-31-25-190 kernel: audit: type=1400 audit(1503579555.012:823): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/20089/sta
Aug 24 12:59:16 ip-172-31-25-190 systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE

每当我取消注释 /etc/mysql/mysql.conf.d/mysqld.cnf

中的以下行时,就会出现此错误代码

general_log_file = /var/log/mysql/mysql.log
general_log= 1
log_slow_queries = /var/log/mysql/mysql-slow.log
long_query_time = 1
log-queries-not-using-indexes = 1

应该怎么做才能解决这个问题?

1 个答案:

答案 0 :(得分:0)

可能是因为apparmor

AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld"

在同一问题上发现此评论:https://bugs.launchpad.net/ubuntu/+source/mysql-5.7/+bug/1610765/comments/19

修复应该是:

# sudo nano /etc/apparmor.d/usr.sbin.mysqld

将系统资源访问部分编辑为:

# Allow system resource access
/sys/devices/system/cpu/ r,
/sys/devices/system/node/ r,
/sys/devices/system/node/** r,
/proc/** r,