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

ぃ、小莉子 提交于 2020-01-02 09:28:26

问题


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!!!


回答1:


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



回答2:


1.Activate log in .my.cnf

 log        = /var/log/mysql/mysql.log

Error logging goes to syslog. This is a Debian improvement :)

Here you can see queries with especially long duration

log_slow_queries    = /var/log/mysql/mysql-slow.log
long_query_time = 2
log-queries-not-using-indexes
  1. $ ls -l /var/run/ | grep mysqld
  2. $ ps -ef |grep mysql
  3. tail -f /var/log/mysql/mysql.log
  4. restart mysql
  5. (option) delete socket & restart mysql


来源:https://stackoverflow.com/questions/36528518/cant-connect-to-var-run-mysqld-mysqld-sock

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!