无法通过套接字'/tmp/mysql.sock连接到本地MySQL服务器 [英] Can't connect to local MySQL server through socket '/tmp/mysql.sock

查看:971
本文介绍了无法通过套接字'/tmp/mysql.sock连接到本地MySQL服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在测试套件中尝试连接本地MySQL服务器时,
失败,出现错误:

  OperationalError:(2002,无法通过套接字连接到本地MySQL服务器/tmp/mysql.sock(2))

但是,我可以随时通过运行命令行
mysql 程序连接到MySQL。 A ps aux | grep mysql 显示服务器正在运行,
stat /tmp/mysql.sock 确认套接字存在。此外,如果我在中除了子句之外的
调试器,我可以可靠地连接
和完全相同的参数。 p>

这个问题相当可靠地再现,但是它似乎不是100%,
,因为每一次在一个蓝色的月亮,我的测试套件实际上没有运行
触发此错误。当我试图运行 sudo dtruss 它没有复制。



所有的客户端代码都是Python,虽然我不能确定这是相关的。



切换到使用主机 127.0.0.1 会产生错误:

  DatabaseError:无法连接到127.0.0.1上的MySQL服务器(61)


解决方案

  sudo / usr / local / mysql / support -files / mysql.server start 

这对我有用。但是,如果这不行,请确保mysqld正在运行并尝试连接。


When I attempted to connect to a local MySQL server during my test suite, it fails with the error:

OperationalError: (2002, "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)")

However, I'm able to at all times, connect to MySQL by running the command line mysql program. A ps aux | grep mysql shows the server is running, and stat /tmp/mysql.sock confirm that the socket exists. Further, if I open a debugger in except clause of that exception, I'm able to reliably connect with the exact same parameters.

This issue reproduces fairly reliably, however it doesn't appear to be 100%, because every once in a blue moon, my test suite does in fact run without hitting this error. When I attempted to run with sudo dtruss it did not reproduce.

All the client code is in Python, though I can't figure how that'd be relevant.

Switching to use host 127.0.0.1 produces the error:

DatabaseError: Can't connect to MySQL server on '127.0.0.1' (61)

解决方案

sudo /usr/local/mysql/support-files/mysql.server start 

This worked for me. However, if this doesnt work then make sure that mysqld is running and try connecting.

这篇关于无法通过套接字'/tmp/mysql.sock连接到本地MySQL服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆