简体   繁体   English

尝试了所有事情仍然得到 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in mac

[英]Tried every thing still getting ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in mac

Every time I run XAMPP and try to run $mysql -u root -p , its throwing me an error which is:每次我运行 XAMPP 并尝试运行$mysql -u root -p ,它都会向我抛出一个错误,即:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) ERROR 2002 (HY000): 无法通过 socket '/tmp/mysql.sock' 连接到本地 MySQL 服务器 (2)

I am using XAMPP version 1.7.3 in Mac OS-10.9.我在 Mac OS-10.9 中使用 XAMPP 1.7.3 版。 Starting Apache and MySQL is not a problem and I have confirmed Apache has started by going to activity monitor.启动 Apache 和 MySQL 不是问题,我已通过转到活动监视器确认 Apache 已启动。

Few things I tried:我尝试了几件事:

  1. checked if MySQL is running by typing this command in terminal: mysqladmin -u root -p status .通过在终端中键入以下命令来检查 MySQL 是否正在运行: mysqladmin -u root -p status Result was:结果是:

    mysqladmin: connect to server at 'localhost' failed error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)' Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists! mysqladmin: connect to server at 'localhost' failed error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)' 检查 mysqld 是否正在运行并且套接字:'/tmp/mysql .sock' 存在!

  2. I checked and found mysql.sock file in /var/mysql/mysql.sock .我检查并在/var/mysql/mysql.sock找到了 mysql.sock 文件。

Things that could have triggered this error but cant say what is wrong:可能触发此错误但无法说明问题所在的事情:

  1. I recently upgraded my OS to Mavericks from Mountain Lion.我最近将我的操作系统从 Mountain Lion 升级到了 Mavericks。
  2. I had also installed separate MySQL to work with Ruby on Rails.我还安装了单独的 MySQL 来使用 Ruby on Rails。 I have made sure that version is off.我已确保该版本已关闭。

Without fixing this problem I am not able to do any development locally and connecting MySQL in PHP script seems impossible.如果不解决这个问题,我将无法在本地进行任何开发,并且在 PHP 脚本中连接 MySQL 似乎是不可能的。 So any help will be appreciated.所以任何帮助将不胜感激。

Here is error_log file from /applications/xampp/xamppfiles/logs/error_log :这是来自/applications/xampp/xamppfiles/logs/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  

   

Finally manage to solve it.最后设法解决它。 First I was looking on wrong directory, I should have looked into /applications/xampp/xamppfiles/ .首先,我查看了错误的目录,我应该查看/applications/xampp/xamppfiles/

List of things I did:我做过的事情清单:

  1. there was not tmp folder under /applications/xampp/xamppfiles, so I created it (mkdir tmp). /applications/xampp/xamppfiles 下没有 tmp 文件夹,所以我创建了它(mkdir tmp)。

  2. I searched for mysql.sock file and found it under /applications/xampp/xamppfiles/var/mysql/mysql.sock .我搜索了 mysql.sock 文件并在/applications/xampp/xamppfiles/var/mysql/mysql.sock下找到了它。

As mysql server connection was not working via socket /tmp/mysql.sock , I used following command to point my /applications/xampp/xamppfiles/var/mysql/mysql.sock to /tmp/mysql.sock file.由于 mysql 服务器连接无法通过 socket /tmp/mysql.sock工作,我使用以下命令将我的/applications/xampp/xamppfiles/var/mysql/mysql.sock指向/tmp/mysql.sock文件。

So this command did the trick:所以这个命令成功了:

ln -s /applications/xampp/xamppfiles/var/mysql/mysql.sock /tmp/mysql.sock
  1. now I restart xampp services and run: mysql -u root -p , I can get into mysql console.现在我重新启动 xampp 服务并运行: mysql -u root -p ,我可以进入 mysql 控制台。 And I also tried connecting mysql from php script and its running ok.而且我还尝试从 php 脚本连接 mysql 并且它运行正常。

After pulling hair for a day and half I finally managed to get it working hope people will find this helpful.在拉了一天半的头发后,我终于设法让它发挥作用,希望人们会发现这有帮助。

Not sure how you get a list of running programs on a mac but you should try and verify that mysqld is actually running.不确定如何获得 mac 上正在运行的程序列表,但您应该尝试验证 mysqld 是否实际正在运行。 (on linux "top -bn1 | grep mysql" would normally show a line of info if it is running, or nothing if it is not.) (在 linux 上,“top -bn1 | grep mysql”如果正在运行,通常会显示一行信息,如果没有,则不显示。)

You could also try stopping mysqld and see if /tmp/mysql.sock vanishes.您也可以尝试停止 mysqld 并查看 /tmp/mysql.sock 是否消失。 If it doesn't then try deleting it and restarting mysql to see if it appears again.如果没有,则尝试删除它并重新启动 mysql 以查看它是否再次出现。 (it should) (这应该)

Do you have any log files that might show what is going on?您是否有任何可能显示正在发生的事情的日志文件?

Looks like your mysql server is not started.看起来你的 mysql 服务器没有启动。 Use the following commands:使用以下命令:

mysqld stop
mysql.server start
ln -s /applications/xampp/xamppfiles/var/mysql/mysql.sock /tmp/mysql.sock

在High Sierra上帮了我大忙。

XAMPP mac has the default settings to store mysql.sock another location. XAMPP mac 的默认设置是将 mysql.sock 存储在另一个位置。 Just change it :)只是改变它:)

$ vim /applications/xampp/xamppfiles/etc/my.cnf

[client]
#password   = your_password
port        =3306
#socket     =/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock
socket      =/tmp/mysql.sock         <---------

...

[mysqld]
user=mysql
port=3306
#socket     =/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock
socket      =/tmp/mysql.sock        <---------

Restart mysql, then works.重新启动mysql,然后工作。

ln -s /applications/xampp/xamppfiles/var/mysql/mysql.sock /tmp/mysql.sock 

That worked for me. 那对我有用。 I have MacOs sierra in my Mac and XAMPP 5.6.30-0 我的Mac和XAMPP 5.6.30-0中都装有MacOs sierra

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Mac Terminal / MySQL配置问题| 错误2002(HY000):无法通过套接字&#39;/tmp/mysql.sock&#39;连接到本地MySQL服务器(2) - Mac Terminal/ MySQL configuration issues | ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) Magento错误:SQLSTATE [HY000] [2002]无法通过套接字&#39;/var/lib/mysql/mysql.sock&#39;连接到本地MySQL服务器 - Magento Error: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' ERROR 2002 (HY000): 无法通过 socket &#39;/var/lib/mysql/mysql.sock&#39; (13) Ubuntu 连接到本地 MySQL 服务器 - ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (13) Ubuntu Mac 上的 Django + XAMPP(2002,“无法通过套接字&#39;/tmp/mysql.sock&#39;(2)连接到本地 MySQL 服务器”) - Django + XAMPP on Mac (2002, "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)") err_connection_timed_out 和 PHP 警告:mysqli_connect():(HY000/2002):Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' - err_connection_timed_out and PHP Warning: mysqli_connect():(HY000/2002):Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' MySQL ERROR 2002 (HY000): 无法通过套接字连接到本地 MySQL 服务器 - MySQL ERROR 2002 (HY000): Can't connect to local MySQL server through socket SQLSTATE [HY000] [2002]无法通过套接字&#39;/var/run/mysqld/mysqld.sock&#39;连接到本地MySQL服务器(2) - SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) mysqli::mysqli(): (HY000/2002): 无法通过套接字'MySQL'连接到本地 MySQL 服务器 (2) - mysqli::mysqli(): (HY000/2002): Can't connect to local MySQL server through socket 'MySQL' (2) 如何修复&#39;ERROR 2002 (HY000): Can&#39;t connect to local MySQL server through socket &#39;/var/run/mysqld/mysqld.sock&#39; (2 &quot;No such file or directory&quot;)&#39; - how fix 'ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")' mysqli_connect():(HY000 / 2002):无法通过套接字连接到本地MySQL服务器 - mysqli_connect(): (HY000/2002): Can't connect to local MySQL server through socket
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM