大网数据广告活动
服务器运维问答

MySQL start error - Failed to create a socket for IPv4 '127.0.0.1': errno: 13

· 52CE 我爱测

I'm pulling my hair out over this one. Out of the blue (seemingly, I hadn't logged into the server in a couple of weeks) mysql died and I haven't been able to restart it. I'm on Ubuntu 14.04. When attempting to restart, the follo…

问题原文

原帖链接 · Orlando · CC BY-SA 3.0

I'm pulling my hair out over this one. Out of the blue (seemingly, I hadn't logged into the server in a couple of weeks) mysql died and I haven't been able to restart it. I'm on Ubuntu 14.04. When attempting to restart, the following shows up in the log:

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

Permissions, you say?

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

That's not it.

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

Doesn't look bad either.

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

I decided to nuke it from orbit:

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

STILL the error persisted. Does anyone have any ideas? At this point I don't mind rebuilding the server from scratch out of frustration, BUT I want to be able to get the data from the database... though I need to be able to connect to it first. Here is my my.cnf file:

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

已采纳解答

原帖链接 · Orlando · CC BY-SA 3.0

In case it helps anyone else, it turns out AppArmor was denying execution. From syslog

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

I don't care enough to diagnose it since I'm going to tear down this server, but I was able to get around it by setting all profiles to complain mode rather than enforce mode:

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

After that, sudo service mysql start worked as intended.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-05-02)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。