我在 ubuntu 14.04 上安装了 mysql 服务器(版本:5.5.54)。我有一个脚本每天优化数据库,然后重新启动 mysql 服务。
今天,我注意到mysql服务器没有正确重启,当我连接到mysql时出现这个错误。
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
在系统日志中,我发现这些消息:
Mar 24 01:20:01 dbs kernel: [35113.530913] init: mysql main process ended, respawning
Mar 24 01:20:01 dbs kernel: [35113.549509] audit_printk_skb: 36 callbacks suppressed
Mar 24 01:20:01 dbs kernel: [35113.549514] audit: type=1400 audit(1490314801.743:24): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="/usr/sbin/mysqld" pid=21133 comm="apparmor_parser"
Mar 24 01:20:01 dbs kernel: [35113.568126] audit: type=1400 audit(1490314801.763:25): apparmor="DENIED" operation="mknod" profile="/usr/sbin/mysqld" name="/run/mysqld/mysqld.err" pid=21145 comm="mysqld" requested_mask="c" denied_mask="c" fsuid=105 ouid=105
mysql apparmor文件
# vim:syntax=apparmor
# Last Modified: Tue Jun 19 17:37:30 2007
#include <tunables/global>
/usr/sbin/mysqld {
#include <abstractions/base>
#include <abstractions/nameservice>
#include <abstractions/user-tmp>
#include <abstractions/mysql>
#include <abstractions/winbind>
capability dac_override,
capability sys_resource,
capability setgid,
capability setuid,
network tcp,
/etc/hosts.allow r,
/etc/hosts.deny r,
/etc/mysql/*.pem r,
/etc/mysql/conf.d/ r,
/etc/mysql/conf.d/* r,
/etc/mysql/*.cnf r,
/usr/lib/mysql/plugin/ r,
/usr/lib/mysql/plugin/*.so* mr,
/usr/sbin/mysqld mr,
/usr/share/mysql/** r,
/var/log/mysql.log rw,
/var/log/mysql.err rw,
/var/lib/mysql/ r,
/var/lib/mysql/** rwk,
/var/lib/mysql-files/ r,
/var/lib/mysql-files/** rwk,
/var/log/mysql/ r,
/var/log/mysql/* rw,
/var/run/mysqld/mysqld.pid rw,
/var/run/mysqld/mysqld.sock w,
/run/mysqld/mysqld.pid rw,
/run/mysqld/mysqld.sock w,
/sys/devices/system/cpu/ r,
# Site-specific additions and overrides. See local/README for details.
#include <local/usr.sbin.mysqld>
}