尝试每件事仍然得到ERROR 2002(HY000):无法通过socket'/tmp/mysql.sock'(2)连接到本地MySQL服务器

问题描述 投票:8回答:4

每次我运行xampp并尝试运行$ mysql -u root -p时,它抛出我的错误是:ERROR 2002(HY000):无法通过套接字'/tmp/mysql.sock'连接到本地MySQL服务器(2) )

我在mac OS-10.9中使用xampp 1.7.3版。启动Apache和mysql不是问题,我已经确认apache已经开始进入活动监视器。 ![在此处输入图像说明] [1]

我尝试的几件事情:1)通过在终端中绑定此命令来检查mysql是否正在运行:mysqladmin -u root -p status RESULT WAS:mysqladmin:在'localhost'连接到服务器失败错误:'无法连接到本地MySQL服务器通过socket'/tmp/mysql.sock'(2)'检查mysqld是否正在运行,并且socket:'/ tmp / mysql.sock'存在!

2)我检查并在/var/mysql/mysql.sock'中找到了mysql.sock文件。

可能引发此错误但无法说出错误的事情:1)我最近将我的操作系统从Mountain Lion升级到Mavricks。 2)我还安装了单独的mysql来处理rails上的ruby。我已经确定该版本已关闭。

没有解决这个问题,我无法在本地进行任何开发,并且在php脚本中连接mysql似乎是不可能的。所以任何帮助将不胜感激。

这是来自/ applications / xampp / xamppfiles / logs / error_log的error_log文件

[Sat Nov 02 09:56:31 2013] [notice] caught SIGTERM, shutting down
[Sat Nov 02 09:56:39 2013] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Sat Nov 02 09:56:40 2013] [notice] Digest: generating secret for digest authentication ...
[Sat Nov 02 09:56:40 2013] [notice] Digest: done
[Sat Nov 02 09:56:40 2013] [notice] Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations
[Sat Nov 02 12:55:47 2013] [notice] caught SIGTERM, shutting down
[Sat Nov 02 13:40:16 2013] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Sat Nov 02 13:40:18 2013] [notice] Digest: generating secret for digest authentication ...
[Sat Nov 02 13:40:18 2013] [notice] Digest: done
[Sat Nov 02 13:40:18 2013] [notice] Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations
[Sat Nov 02 15:12:39 2013] [notice] caught SIGTERM, shutting down
[Sat Nov 02 20:54:41 2013] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Sat Nov 02 20:54:43 2013] [notice] Digest: generating secret for digest authentication ...
[Sat Nov 02 20:54:43 2013] [notice] Digest: done
[Sat Nov 02 20:54:44 2013] [notice] Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations
[Sat Nov 02 21:10:53 2013] [notice] caught SIGTERM, shutting down
[Sat Nov 02 21:10:57 2013] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Sat Nov 02 21:10:58 2013] [notice] Digest: generating secret for digest authentication ...
[Sat Nov 02 21:10:58 2013] [notice] Digest: done
[Sat Nov 02 21:10:58 2013] [notice] Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations
[Sat Nov 02 21:31:39 2013] [notice] caught SIGTERM, shutting down
[Sat Nov 02 21:31:44 2013] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Sat Nov 02 21:31:47 2013] [notice] Digest: generating secret for digest authentication ...
[Sat Nov 02 21:31:47 2013] [notice] Digest: done
[Sat Nov 02 21:31:47 2013] [notice] Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations
[Sat Nov 02 21:45:07 2013] [notice] caught SIGTERM, shutting down
[Sun Nov 03 08:50:06 2013] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Sun Nov 03 08:50:09 2013] [notice] Digest: generating secret for digest authentication ...
[Sun Nov 03 08:50:09 2013] [notice] Digest: done
[Sun Nov 03 08:50:10 2013] [notice] Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations  
php mysql macos sockets
4个回答
11
投票

最后设法解决它。首先我看错了目录,我应该看看/applications/xampp/xamppfiles/

我所做的事情清单:

  1. / applications / xampp / xamppfiles下没有tmp文件夹,所以我创建了它(mkdir tmp)。
  2. 我搜索了mysql.sock文件,并在/applications/xampp/xamppfiles/var/mysql/mysql.sock下找到它。

由于mysql服务器连接无法通过套接字/tmp/mysql.sock工作,我使用以下命令将我的/applications/xampp/xamppfiles/var/mysql/mysql.sock指向/tmp/mysql.sock文件。

所以这个命令做了诀窍:

ln -s /applications/xampp/xamppfiles/var/mysql/mysql.sock /tmp/mysql.sock
  1. 现在我重新启动xampp服务并运行:mysql -u root -p,我可以进入mysql控制台。我也尝试从php脚本连接mysql并运行正常。

拔头发一天半后我终于设法让它工作希望人们会觉得这很有帮助。


0
投票

不知道如何在mac上获得正在运行的程序列表,但是你应该尝试验证mysqld是否实际运行。 (在Linux上“top -bn1 | grep mysql”通常会显示一行信息,如果它正在运行,或者如果不是则没有。)

您也可以尝试停止mysqld并查看/tmp/mysql.sock是否消失。如果没有,则尝试删除它并重新启动mysql以查看它是否再次出现。 (这应该)

你有任何可能显示正在发生的事情的日志文件吗?


0
投票

看起来你的mysql服务器没有启动。使用以下命令:

mysqld stop
mysql.server start

-2
投票

ln -s /applications/xampp/xamppfiles/var/mysql/mysql.sock /tmp/mysql.sock为我工作! Mac OS X Mavericks,运行XAMPP 1.8.2 - 摩根德莱尼2014年10月6日17:04

这对我也有用。我的Mac和XAMPP 5.6.30-0中有MacOs sierra

© www.soinside.com 2019 - 2024. All rights reserved.