Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I really don't understand how all those privileges work in Linuxes.

To start MySQL server mysqld program has to write its .pid files to /var/run/mysqld/ directory. But we know from FHS (Filesystem Hierarchy Standard) that:

Files under this directory must be cleared (removed or truncated as appropriate) at the beginning of the boot process.

So mysqld has to create /mysqld directory under /var/run/ every time MySQL server is started.

The owner and group of /var is root and /var is:

drwxr-xr-x  13 root root  4096 may 20 23:41 var.

And we also know from FHS (Filesystem Hierarchy Standard) that:

/var/run should be unwritable for unprivileged users (root or users running daemons); it is a major security problem if any user can write in this directory.

So mysqld cannot write to the directory. Indeed when I run mysqld to start MySQL server I always get an error:

user@user-desktop:~$ sudo mysqld --console
130720 23:43:02 [ERROR] Can't start server : Bind on unix socket: Permission denied
130720 23:43:02 [ERROR] Do you already have another mysqld server running on socket: /var/run/mysqld/mysqld.sock ?
130720 23:43:02 [ERROR] Aborting

The question is: how mysqld can write .pid files to /var/run/mysqld/ if standard forbids to open this directory for writing? This is a clear contradiction, isn't it?

My question is: how to let mysqld to create and write its files to /var/run/mysqld/ without changing permissions of the /var/run directory? For now I see the only way:

user@user-desktop:$ sudo chmod a+w /var

But it is forbidden by the Standard.

share|improve this question
Did you install mysql-server or something else? – Thomas Ward Jul 21 '13 at 20:17

/var/run should be unwritable for unprivileged users means that root and sudo accounts (as these are privileged users) are allowed to write to it.

The upstart script for MySQL is started as root and then is allowed to create a file or directory in /var/run. And this file is created with the permission as set in the configuration. This should be /etc/my.cnf and it will have something like this:

user   = mysql
socket = /var/lib/mysql/mysql.sock

You should have something related to mysql in /etc/init.d After I installed MySQL Server I get this:

enter image description here

Are you sure you did not install the MySQL Client?

share|improve this answer
What is "upstart script for MySQL"? Is it mysqld? Unfortunately mysqld cannot create directories under /var/run/ on my system automaticly. I don't know why. Where may I configure mysqld settings? – Green Jul 21 '13 at 17:08
- yes mysqld. It is in /etc/init.d - it uses /etc/my.cnf (default that is) for settings and permissions. – Rinzwind Jul 21 '13 at 18:02
For some reason I don't have mysqld in /etc/init.d/. It is in /usr/sbin/mysqld. I followed this post and just changed socket and pid-file paths in /etc/my.cnf to different directory. Now all works fine. However I don't know if this is a right way. Nevertheless, thank you for your attention. – Green Jul 21 '13 at 19:11
see update @green you must be doing something wrong ;) – Rinzwind Jul 21 '13 at 20:13
@Rinzwind can you please help me with… – barraponto Mar 27 '14 at 12:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.