大网数据广告活动
服务器运维问答

How to get mysql.sock file, mistakenly deleted from "/mysql/tmp/"

· 52CE 我爱测

I was stuck with a PDO Exception PDOException: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in lock_may_be_available() (line 167 of home/../includes/lock.inc). In order to resolv…

问题原文

原帖链接 · GIRI · CC BY-SA 4.0

I was stuck with a PDO Exception

PDOException: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in lock_may_be_available() (line 167 of home/../includes/lock.inc).

In order to resolve that I tried to recreate the symbolic link using the command. I'm working on the Linux server.

 ln -s /home/../mysql/tmp/mysql.sock /tmp/mysql.sock

when executed the above sql statement, there was no change with the PDO exception. And later, I mistakenly deleted the mysql.sock file in "/home/../mysql/tmp/" (not in "/tmp").

How do I get back or re-create the mysql.sock file. Any idea regarding the PDO exception and how to resolve it.

已采纳解答

原帖链接 · Louis Papaloizou · CC BY-SA 3.0

vi /etc/mysql/my.cnf

You will find the lines below top in your configuration file

[client]
port            = 3306
socket          = /var/run/mysqld/mysqld.sock

Make sure mysqld.sock is where it is supposed to be I don't like the path in your error message "/tmp/mysql.sock"

Since you are here look for this line as well

bind-address            = 127.0.0.1

If you are trying to connect from a remote location comment this line out.

Try to connect locally (from a terminal on the server)

mysql -u root -p

If security is not a concern for you (i.e it's your personal server not a multiuser environment) you can also make sure the file is readable by anyone

chmod a+r /var/run/mysqld/mysqld.sock

All the above should solve your connectivity issues. To get the file you could do a fresh installation of mysql server.

apt-get purge mysql-server
apt-get install mysql-server

Or you can download the mysql-server .deb package extract it and you should find it somewhere in there. Equivalently .rpm if you are using RHL.

Edit: Since you've been copying files around maybe the file ownership changed to root, check that also (with ls-la /path). Owner should be mysql group mysql. Can't think of anything else.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2014-08-01)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0 / CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。