MySQL 启动错误-无法为 IPv4‘127.0.0.1’创建套接字:errno:13

MySQL 启动错误-无法为 IPv4‘127.0.0.1’创建套接字:errno:13

我为此绞尽了脑汁。突然(似乎我已经有几周没有登录服务器了)mysql 死机了,我无法重新启动它。我使用的是 Ubuntu 14.04。尝试重新启动时,日志中显示以下内容:

170502 18:00:57 [Note] Server hostname (bind-address): '127.0.0.1'; port: 3306
170502 18:00:57 [Note]   - '127.0.0.1' resolves to '127.0.0.1';
170502 18:00:57 [ERROR] Failed to create a socket for IPv4 '127.0.0.1': errno: 13.
170502 18:00:57 [ERROR] Can't create IP socket: Permission denied
170502 18:00:57 [ERROR] Aborting

你说的是权限?

root@mleserver:~# ls -ld /var/run/mysqld/
drwxr-xr-x 2 mysql mysql 40 May  2 16:46 /var/run/mysqld/

不是这个。

root@mleserver:~# ls -la /var/lib/mysql
total 2521564
drwx------ 10 mysql mysql       4096 May  2 18:00 .
drwxr-xr-x 55 root  root        4096 May  2 16:51 ..
-rw-r--r--  1 mysql mysql          0 Oct  9  2013 debian-5.1.flag
-rw-r--r--  1 mysql mysql          0 May  2 17:50 debian-5.5.flag
-rw-rw----  1 mysql mysql 2569011200 May  2 18:00 ibdata1
-rw-rw----  1 mysql mysql    5242880 May  2 18:00 ib_logfile0
-rw-rw----  1 mysql mysql    5242880 May  2 18:00 ib_logfile1
drwx------  2 mysql mysql       4096 Aug 15  2016 mleserver_production
drwx------  2 mysql mysql       4096 May  2 17:50 mysql
-rw-rw----  1 mysql mysql          6 Jan 20 06:47 mysql_upgrade_info
drwx------  2 mysql mysql       4096 May  2 17:50 performance_schema

看上去也不错。

root@mleserver:/tmp# cat /etc/passwd
...
mysql:x:104:111:MySQL Server,,,:/nonexistent:/bin/false

我决定从轨道上用核武器轰炸它:

sudo apt-get remove --purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get install mysql-server mysql-client

错误仍然存​​在。有人有什么想法吗?此时我不介意出于沮丧而从头开始重建服务器,但我希望能够从数据库中获取数据……尽管我需要先连接到它。这是我的 my.cnf 文件:

[client]
port            = 3306
socket          = /var/run/mysqld/mysqld.sock

[mysqld_safe]
socket          = /var/run/mysqld/mysqld.sock
nice            = 0

[mysqld]
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking

bind-address            = 127.0.0.1
key_buffer              = 16M
max_allowed_packet      = 16M
thread_stack            = 192K
thread_cache_size       = 8

myisam-recover         = BACKUP

query_cache_limit       = 1M
query_cache_size        = 16M

log_error = /var/log/mysql/error.log

expire_logs_days        = 10
max_binlog_size         = 100M

[mysqldump]
quick
quote-names
max_allowed_packet      = 16M

[mysql]

[isamchk]
key_buffer              = 16M

!includedir /etc/mysql/conf.d/

答案1

如果它对其他人有帮助,事实证明 AppArmor 拒绝执行。来自系统日志

May  2 23:35:51 devanalyzer kernel: [24540.913056] type=1400 audit(1493782551.291:50): apparmor="DENIED" operation="create" parent=1 profile="/usr/sbin/mysqld" pid=25601 comm="mysqld" family="inet" sock_type="stream" protocol=6

由于我要关闭这台服务器,所以我不太关心如何诊断它,但我能够通过将所有配置文件设置为投诉模式而不是强制模式来解决这个问题:

sudo aa-complain /etc/apparmor.d/*

此后,sudo service mysql start一切按预期进行。

相关内容