root - MySQL can't create pid file: Permission Denied

08
2014-07
  • Pierre

    I'm using MySQL on my macbook pro, which worked fine for the last 2 years. A week ago it suddenly stopped and I'm not able to restart it again.

    I've changed the permission on /usr/local/mysql to 0777 and also changed the owner to mysql.

    When I try to start mysql (sudo /usr/local/mysql/bin/mysqld_safe or sudo /usr/local/mysql/support-files/mysql.server start), I get onf of the following errors:

    ERROR! The server quit without updating PID file (/usr/local/mysql/data/[COMPUTERNAME].pid)

    or

    mysqld_safe mysqld from pid file /usr/local/mysql/data/[COMPUTERNAME].pid ended.

    When I open the .err file, I see this errors:

    140222 8:10:30 [ERROR] /usr/local/mysql/bin/mysqld: Can't create/write to file '/usr/local/mysql/data/[COMPUTERNAME].pid' (Errcode: 13)

    140222 8:10:30 [ERROR] Can't start server: can't create PID file: Permission denied

    Edit:

    Here is the ouput of sudo ls -ld / /usr /usr/local /usr/local/mysql /usr/local/mysql/data /usr/local/mysql-5.6.16-osx10.7-x86_64

    drwxr-xr-x  36 root    wheel  1292 Feb 20 21:16 /
    drwxr-xr-x@ 12 root    wheel   408 Oct 26 10:12 /usr
    drw-r--r--  49 root    wheel  1666 Feb 22 09:06 /usr/local
    lrwxr-xr-x   1 root    wheel    27 Feb 22 09:06 /usr/local/mysql -> mysql-5.6.16-osx10.7-x86_64
    drwxr-xr-x  17 _mysql  wheel   578 Feb 22 09:06 /usr/local/mysql-5.6.16-osx10.7-x86_64
    drwxr-xr-x  10 _mysql  wheel   340 Feb 22 09:07 /usr/local/mysql/data
    

    Running ls -ld /usr/local/mysql/data/*.pid gives ls: /usr/local/mysql/data/*.pid: No such file or directory

  • Answers
  • JdeBP

    drw-r--r-- 49 root wheel 1666 Feb 22 09:06 /usr/local

    There you have it, right in front of you. Execute (directory traversal) permission denied. To the mysql user and indeed to everyone else.

    The permissions and ownership of /usr/local are a widely-hit problem in Mac OS 10, for many reasons that I'm not going to elaborate here.

    chmod a+x /usr/local
    (run as the superuser of course) is your friend.

    Avoid suggestions to change the ownership or group of the directory. They are a security disaster waiting to happen, as several people have noted in places where this has come up before.


  • Related Question

    installation - Why can't I connect to my MySQL server that I just installed?
  • user28588

    I am trying to install mysql 5.1.42 and after running below line

    sudo /usr/local/mysql/bin/mysqladmin -u root -p password
    

    I get this error:

    /usr/local/mysql/bin/mysqladmin: connect to server at 'localhost' failed
    error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
    Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!
    

    I have created mysqld.sock and gave permission to it too, but I still get the same error.


  • Related Answers
  • Martin Hilton

    The MySQL server should create the /var/run/mysqld/mysqld.sock when it starts, you shouldn't need to create it yourself. The most likely problem is that the MySQL server isn't running. You can check this by running ps ax | grep mysqld this will show you the server process if there is one. If it isn't running then start it and give that command another go.