Can't connect to '/var/run/mysqld/mysqld.sock'

Fo Tastisch picture Fo Tastisch · Apr 10, 2016 · Viewed 9.6k times · Source

This is my first post here, so I hope I do everything right and don't forget any important info. I'm glad for any hints, because I'm running out of ideas (if I ever had any ;)).

I am (or was) running owncloud on Raspbian Jessie (so I guess basically Debian). Suddenly owncloud stopped working. The nginx error points towards php5-fpm, further searches gave this error:

exception 'Doctrine\DBAL\DBALException' with message 'Failed to connect to the database: An exception occured in driver: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)' in /var/www/owncloud/lib/private/db/connection.php:54

So it looks like a mysql error, and /var/run/mysqld/ is actually empty.

Following these posts 1 and 2, I tried

sudo find / -type s

resulting in this output:

/run/php5-fpm.sock
/run/fail2ban/fail2ban.sock
/run/thd.socket
/run/dhcpcd.unpriv.sock
/run/dhcpcd.sock
/run/dbus/system_bus_socket
/run/avahi-daemon/socket
/run/udev/control
/run/systemd/journal/syslog
/run/systemd/journal/socket
/run/systemd/journal/stdout
/run/systemd/journal/dev-log
/run/systemd/shutdownd
/run/systemd/private
/run/systemd/notify
find: `/proc/30933/task/30933/fd/5': No such file or directory
find: `/proc/30933/task/30933/fdinfo/5': No such file or directory
find: `/proc/30933/fd/5': No such file or directory
find: `/proc/30933/fdinfo/5': No such file or directory

In the processes with top on the other hand, mysqld and mysqld_safe show up. mysql-client, mysql-server and php5-mysql are installed and updated to the latest versions.

I also had a look at

/etc/mysql/my.cnf
/etc/mysql/debian.cnf

both show /var/run/mysqld/mysqld.sock as socket...

/var/lib/mysql/my.cnf

mentioned here does not exist.

Additionally, it seems that I can't connect to mysql through

mysql -u user -p

at least it results in the Error 2002 as well.

Finally, I tried stopping and starting the mysql service. This resulted in the following output of

systemctl status mysql.service

mysql.service - LSB: Start and stop the mysql database server daemon
Loaded: loaded (/etc/init.d/mysql)
Active: failed (Result: exit-code) since So 2016-04-10 11:54:23 CEST; 23s ago
Process: 9777 ExecStop=/etc/init.d/mysql stop (code=exited, status=0/SUCCESS)
Process: 12878 ExecStart=/etc/init.d/mysql start (code=exited, status=1/FAILURE)

So I'm kind of lost what is going on, the problem occurs since some updates a few days ago. While writing this post, I went through all the steps again, just to be safe. At one point, I had a short glimpse at my owncloud instance in the browser, but then it was gone again. So I appreciate any help/hints!!!

Thank you very much!!!

Answer

seb_dom picture seb_dom · Nov 29, 2017

I faced the issue: Can't connect to '/var/run/mysqld/mysqld.sock'. The problem was that mysql service was not started after installation. Once I run the following command, then it worked properly:

systemctl start mysql.service
mysql -u root -p