Mysqld does not start: Bind on unix socket: Permission denied

Bug #876268 reported by Manolinux
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
mysql-5.1 (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

I updated to oneiric and mysqld does not start. It seems it can't create the socket /var/run/mysqld/mysqld.sock

What the log /var/log/mysql/error.log says:

===

11017 9:44:12 [Note] Plugin 'FEDERATED' is disabled.
111017 9:44:12 InnoDB: Initializing buffer pool, size = 8.0M
111017 9:44:12 InnoDB: Completed initialization of buffer pool
111017 9:44:12 InnoDB: Started; log sequence number 0 363147242
111017 9:44:12 [ERROR] Can't start server : Bind on unix socket: Permission denied
111017 9:44:12 [ERROR] Do you already have another mysqld server running on socket: /var/run/mysqld/mysqld.sock ?
111017 9:44:12 [ERROR] Aborting

===

But, I have the appropiate permisions:

===
$ ls -la /var/run/mysqld
total 0
drwxr-xr-x 2 mysql root 40 2011-10-17 09:29 .
drwxr-xr-x 31 root root 1040 2011-10-17 09:17 ..

===

And I checked mysqld runs as the appropiate user:

===
mysql 12938 1 2 09:33 ? 00:00:00 /usr/sbin/mysqld
===

Trying mysql_safe:

===
$ sudo mysqld_safe
[sudo] password for manolinux:
111017 09:49:26 mysqld_safe Logging to syslog.
111017 09:49:26 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
111017 09:49:32 mysqld_safe mysqld from pid file /var/lib/mysql/min.pid ended
===

ProblemType: Bug
DistroRelease: Ubuntu 11.10
Package: mysql-server-5.1 5.1.58-1ubuntu1
ProcVersionSignature: Ubuntu 3.0.0-12.20-generic 3.0.4
Uname: Linux 3.0.0-12-generic x86_64
ApportVersion: 1.23-0ubuntu3
Architecture: amd64
Date: Mon Oct 17 09:38:02 2011
ProcEnviron:
 LANGUAGE=es_ES:en_US:en
 PATH=(custom, user)
 LANG=es_ES.UTF-8
 LC_MESSAGES=es_ES.UTF-8
 SHELL=/bin/bash
SourcePackage: mysql-5.1
UpgradeStatus: Upgraded to oneiric on 2011-10-14 (2 days ago)
mtime.conffile..etc.apparmor.d.usr.sbin.mysqld: 2010-12-27T16:46:29

Revision history for this message
Manolinux (mu) wrote :
Revision history for this message
Manolinux (mu) wrote :

I found the problem.

It was on /etc/apparmor.d/usr.sbin.mysqld , which clever unbuntu-bug found it was modified.

During upgrade, I was asked whether to substitute this file with a new version, but since I needed some of the current configuration and since I thought the changes where cosmetic (but they were not!), I choosed to keep my file.

I compared my file with the base version and applied the changes myself, and it worked. The changes were:

===
diff -u /etc/apparmor.d/usr.sbin.mysqld.bak /etc/apparmor.d/usr.sbin.mysqld
--- /etc/apparmor.d/usr.sbin.mysqld.bak 2011-10-17 10:02:03.000000000 +0200
+++ /etc/apparmor.d/usr.sbin.mysqld 2011-10-17 10:02:33.000000000 +0200
@@ -33,8 +33,8 @@
   /var/lib/mysql/** rwk,
   /var/log/mysql/ r,
   /var/log/mysql/* rw,
- /var/run/mysqld/mysqld.pid w,
- /var/run/mysqld/mysqld.sock w,
+ /{,var/}run/mysqld/mysqld.pid w,
+ /{,var/}run/mysqld/mysqld.sock w,

   /sys/devices/system/cpu/ r,
   /home/manolinux/.opentpv/** rw,
===

Sorry to disturb you, Ubuntu develpers, but I hope at least this report helps other people with similar problems.

Thanks.

Revision history for this message
Jerry Ablan (lucifurious) wrote :

I can confirm this works and starts mysql.

Revision history for this message
Serge Hallyn (serge-hallyn) wrote :

Thanks for the report and further information. I'm glad you were able to resolve it.

Changed in mysql-5.1 (Ubuntu):
status: New → Invalid
Revision history for this message
William Dawkins (wdawkins) wrote :

1. This exposes a logging failure as well. The mysql error log gives no clue that the problem binding the socket stems from apparmor. The mysql error output and associated documentation should offer enough information to distinguish the cause of the permission denial.

2. In the course of trying to fix this, I ran into another bug-- the stop script for the mysql service does not work properly.

It was especially problematic when I attempted to reinstall mysql at one point using Synaptic, and it hung trying to stop mysqld. My workaround was to temporarily rename /usr/sbin/mysqld, which allowed /usr/bin/mysqld_safe to fail cleanly, and Synaptic was able to complete the reinstall. I expect that the problem was at the dpkg level, not specific to a GUI front end package manger. See (2) below for detail.

--- Detail ---

1) Error log in mysql not informative enough
I had mysql fail from this cause after upgrading an ubuntu machine to oneiric. After checking the mysql log and confirming that no other mysql instance was running, I began with a google search for the error and a look at the mysql documentation. These led me to check for mysql user and directory permissioning issues.

When this did not resolve the problem, I lost considerable time rechecking permissions, tracing configuration files and startup scripts, reinstalling/repermissioning the mysql user and directories, etc. to no avail.

I grant in hindsight that after checking mysql's error.log, I should have checked dmesg for syslogd output (see below). This would at least have pointed me towards apparmor as a potential root cause. However, I think many users will not know to do this, as demonstrated by threads in other forums where users appear to still be stuck (I will be referring them to this bug).

# dmesg

. . .

[ 671.841551] type=1400 audit(1321280685.638:63): apparmor="STATUS" operation="profile_replace" name="/usr/sbin/mysqld" pid=5696 comm="apparmor_parser"
[ 671.912172] type=1400 audit(1321280685.710:64): apparmor="DENIED" operation="mknod" parent=1 profile="/usr/sbin/mysqld" name="/run/mysqld/mysqld.sock" pid=5700 comm="mysqld" requested_mask="c" denied_mask="c" fsuid=115 ouid=115
[ 677.140067] init: mysql main process (5700) terminated with status 1

. . .

2) The ubuntu startup process eventually launches /usr/bin/mysqld_safe, which attempts to restart /usr/sbin/mysqld each time it fails. Hence, when mysqld cannot bind the socket due to the problem in /etc/apparmor.d/usr.sbin.mysqld and exits, mysqld_safe restarts it.

It looks like the control scripts do not work as expected because they do not stop mysqld_safe. Neither "stop mysql" nor "/etc/init.d/mysql stop" (as root) work properly.

Revision history for this message
quiricada (raraland) wrote :

ubuntu 3.0.0-16-generic-pae
mysql 5.1

same problem here, after a grand tour via google, manolinux saved the bacon.

thanks

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.