Search code examples
mysqlsocketsubuntu-14.04boot

Cannot connect to MySQL Server after reboot: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)


I could not find a solution for my mysql problem in one of the other mysql Error 2002 questions.

After a reboot of my Ubuntu 14.04 LTS, mysql deamon seems to run, but wont accept connections. Restarting makes it work, but after a next reboot it has the same issue again. I tried this being logged in as my normal user and being logged in as root, but same behaviour occurs:

:~# mysql
  ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
:~# ps aux | grep mysql
  mysql      899  0.1 23.0 1266432 472632 ?      Ssl  10:47   0:00 /usr/sbin/mysqld
  root      3590  0.0  0.0  11740   936 pts/1    R+   11:00   0:00 grep --color=auto mysql
:~# service mysql start
  start: Job is already running: mysql
:~# service mysql restart
  mysql stop/waiting
  mysql start/running, process 3623
:~# mysql
  ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
:~# ps aux | grep mysql
  mysql     3623  0.1 22.6 1134968 464648 ?      Ssl  11:00   0:00 /usr/sbin/mysqld
  root      4272  0.0  0.0  11740   936 pts/1    R+   11:05   0:00 grep --color=auto mysql

Same user, same process as it seems to me. What is the difference? How can I solve this?

Thanks, Jos


Solution

  • For anyone facing the same problem ever.

    Turns out that a while ago I ran:

    sudo update-rc.d mysql defaults
    

    I did this when I noticed MySQL server was not running after a boot. I concluded that starting at boot was not configured, but I was wrong there. It was configured, but MySQL stopped for some reason after being started at boot. The 2 ways of starting MySQL at boot were biting and causing the problem. Running this solved it for me:

    sudo update-rc.d -f mysql remove