简体   繁体   English

无法在 Mac 上连接到 MySQL -- 缺少 mysql.sock 文件

[英]Can't connect to MySQL on Mac -- missing mysql.sock file

I installed MySQL on my Mac OS 10.6 about a week ago, and, after some playing around, got it to work just fine.大约一周前,我在我的 Mac OS 10.6 上安装了 MySQL,并且在玩了一段时间之后,让它工作得很好。 It integrated with python MySQLdb and I also got Sequel Pro to connect to the database.它与 python MySQLdb 集成,我还使用 Sequel Pro 连接到数据库。 However, php wouldn't access the server.但是,php 不会访问服务器。 Even after I added a php.ini file to /etc/ and directed it toward the same sock that Sequel Pro was using: /tmp/mysql.sock.即使在我将 php.ini 文件添加到 /etc/ 并将其指向 Sequel Pro 使用的同一个袜子之后:/tmp/mysql.sock。

But now I can't access the local server at all.但是现在我根本无法访问本地服务器。 As far as I can tell, there is no mysql.sock file anywhere on my computer, not in /tmp/ or anywhere else.据我所知,我的计算机上的任何地方都没有 mysql.sock 文件,不在 /tmp/ 或其他任何地方。

I can start the mysql server from Terminal, but it logs me out automatically after a minute:我可以从终端启动 mysql 服务器,但一分钟后它会自动将我注销:

110425 17:36:18 mysqld_safe Logging to '/usr/local/mysql/data/dn0a208bf7.sunet.err'.
110425 17:36:18 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
110425 17:37:58 mysqld_safe mysqld from pid file /usr/local/mysql/data/dn0a208bf7.sunet.pid ended

If I try to call "mysql" from the command line (which worked perfectly earlier today):如果我尝试从命令行调用“mysql”(今天早些时候工作得很好):

ERROR 2002 (HY000): Can\'t connect to local MySQL server through socket '/tmp/mysql.sock' (2)

The PHP error is of course similar: PHP错误当然是类似的:

PHP Warning:  mysql_real_escape_string(): [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock)

Also, there is no "my.cnf" file in my mysql installation directory: /usr/local/mysql.另外,在我的 mysql 安装目录中没有“my.cnf”文件:/usr/local/mysql。 There are my.cnf files for the mysql installations that come along with XAMPP. XAMPP 附带了用于 mysql 安装的 my.cnf 文件。 Those also have the default socket listed as '/tmp/mysql.sock', but I had to change them manually.那些也将默认套接字列为“/tmp/mysql.sock”,但我必须手动更改它们。

Any ideas what's going on?任何想法发生了什么? Why would modifying the php.ini file have produced a change for Sequel Pro as well?为什么修改 php.ini 文件也会对 Sequel Pro 产生变化?

First of all I suggest you to use homebrew to install any third part libraries or tools on your mac.首先,我建议您使用自制软件在您的 mac 上安装任何第三方库或工具。 Have a look to : http://mxcl.github.com/homebrew/看看: http : //mxcl.github.com/homebrew/

Otherwise for your problem you can search where is the mysql socket on your mac and then symlink it to /tmp.否则,对于您的问题,您可以搜索 mac 上的 mysql 套接字在哪里,然后将其符号链接到 /tmp。

In your terminal try something like :在您的终端中尝试类似的操作:

locate mysql | grep sock

You will get something like :你会得到类似的东西:

/the/path/to/mysql.sock

Then do :然后做 :

ln -s /the/path/to/mysql.sock /tmp/mysql.sock

This should works.这应该有效。

Also you can edit your php.ini file to set the correct path for the mysql socket.你也可以编辑你的 php.ini 文件来为 mysql 套接字设置正确的路径。

Hope this help.希望这有帮助。

I was getting some similar error and ended up here.我遇到了一些类似的错误,最后到了这里。 I am using OSX 10.9.5.我使用的是 OSX 10.9.5。 This solved my problems (hope it helps someone).这解决了我的问题(希望它可以帮助某人)。

1) sudo mkdir /var/mysql 1) 须藤 mkdir /var/mysql

2) sudo ln -s /private/tmp/mysql.sock /var/mysql/mysql.sock 2) sudo ln -s /private/tmp/mysql.sock /var/mysql/mysql.sock

More informations: http://glidingphenomena.blogspot.com.br/2010/03/fixing-warning-mysqlconnect-cant.html更多信息: http : //glidingphenomena.blogspot.com.br/2010/03/fixing-warning-mysqlconnect-cant.html

Thanks!谢谢!

I was also getting this error on a fresh install of XAMPP.我在全新安装的 XAMPP 上也遇到了这个错误。

For those not comfortable with the command line, there is another way.对于那些不熟悉命令行的人,还有另一种方法。

Based on the advice above (thank you), I used my old standard "Easy Find" to locate the latest version of my.cnf.根据上面的建议(谢谢),我使用我的旧标准“轻松查找”来定位最新版本的 my.cnf。 Upon opening the file in an editor I discovered that the socket file was pointing to:在编辑器中打开文件后,我发现套接字文件指向:

socket = /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock socket = /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock

I updated Navicat's Advanced properties/ Use socket file to the path above and bingo.我更新了 Navicat 的高级属性/使用套接字文件到上面的路径和宾果游戏。

Hope this helps someone.希望这可以帮助某人。

Ok, I just spent a couple hours struggling with this same problem.好的,我只是花了几个小时来解决同样的问题。 I had installed the dmg file for MySql 5.5.20 (64bit) for osx 10.6 on my iMac with OSX 10.7.2 - and the /tmp/mysql.sock was missing!我已经在装有 OSX 10.7.2 的 iMac 上为 osx 10.6 安装了 MySql 5.5.20(64 位)的 dmg 文件 - 并且 /tmp/mysql.sock 丢失了!

The answer turned out to be simply install the MySQLStartupItem.pkg that comes with the dmg file and restart the system.答案原来是简单地安装 dmg 文件附带的 MySQLStartupItem.pkg 并重新启动系统。 This starts up the daemons upon startup (which I hoped would be optional).这会在启动时启动守护进程(我希望这是可选的)。

Magically, my /tmp/mysql.sock file appeared and all is well!神奇的是,我的 /tmp/mysql.sock 文件出现了,一切都很好!

I am going to throw in my two cents here because I had this problem too but my circumstances are abnormal for most.我要在这里投入我的两分钱,因为我也有这个问题,但我的情况对大多数人来说都是不正常的。 My system had a blended install of Zend Server CE and XAMPP.我的系统混合安装了 Zend Server CE 和 XAMPP。 I am running Mac OS X. And I decided to remove Zend from my system because it was being a pain in my butt.我正在运行 Mac OS X。我决定从我的系统中删除 Zend,因为它让我很痛苦。

Upon removing Zend, since both were using the same DB and Zend had it my system went crazy.删除 Zend 后,由于两者都使用相同的数据库并且 Zend 拥有它,我的系统变得疯狂。 Uninstalling and reinstalling XAMPP didn't help.卸载并重新安装 XAMPP 没有帮助。 After a couple hours (which I just literally got done with) of troubleshooting I found that I needed to search my system for all copies my.cnf.经过几个小时(我刚刚完成)故障排除后,我发现我需要在我的系统中搜索 my.cnf 的所有副本。 The reason being is that mysql still kept trying to look for the Zend mysql path and it was failing.原因是 mysql 仍然不断尝试寻找 Zend mysql 路径,但失败了。

So I used locate to find it.所以我使用 locate 来找到它。 I had to initiate locate (since I had never used it before) so that it could build a DB of files on my system.我必须启动定位(因为我以前从未使用过它),以便它可以在我的系统上构建一个文件数据库。 Then I ran "locate my.cnf" and I found one in "/private/etc".然后我运行“locate my.cnf”并在“/private/etc”中找到了一个。 So I just renamed the file to my.cnf.old and tried to launch MySQL again.所以我只是将文件重命名为 my.cnf.old 并尝试再次启动 MySQL。 Bam!砰! It works now.它现在有效。

I will say this, I had to have a co-worker help me out because I was just spinning my wheels on this one.我会这样说,我不得不让一位同事帮助我,因为我只是在这个轮子上旋转。 I really hope this helps someone out there.我真的希望这可以帮助那里的人。 Thanks!谢谢!

Found the solution:找到了解决办法:
I had the same issue and I did a lot of searches but couldn't solve the issue until I looked at my MySql config file.我遇到了同样的问题,我进行了大量搜索,但在查看 MySql 配置文件之前无法解决问题。 In my config file socket was in line 21 and the path was在我的配置文件中,socket 在第 21 行,路径是
"/Applications/AMPPS/var/mysql.sock" “/Applications/AMPPS/var/mysql.sock”

In Ampps application click on MySql tab and then click on configuration button.在 Ampps 应用程序中,单击 MySql 选项卡,然后单击配置按钮。

You can also find the config file in "/Applications/AMPPS/mysql/etc" folder您还可以在“/Applications/AMPPS/mysql/etc”文件夹中找到配置文件

So simply I added所以我简单地添加了
'unix_socket' => '/Applications/AMPPS/var/mysql.sock', 'unix_socket' => '/Applications/AMPPS/var/mysql.sock',
to my database.php in mysql array and it's worked for me.到我的 mysql 数组中的 database.php,它对我有用。
After host line.主机线后。 I have tested with localhost and 127.0.0.1 and both worked我已经用 localhost 和 127.0.0.1 进行了测试,并且都有效
Hopefully it's working for you too.希望它也对你有用。

如果您已经通过自制软件安装了 mysql,那么简单的brew services restart mysql可能会有所帮助。

暂无
暂无

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

相关问题 Mac 上的 Django + XAMPP(2002,“无法通过套接字'/tmp/mysql.sock'(2)连接到本地 MySQL 服务器”) - Django + XAMPP on Mac (2002, "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)") 警告:mysql_connect():无法通过套接字“ /tmp/mysql.sock”连接到本地MySQL服务器(2) - Warning: mysql_connect(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 无法连接:无法通过套接字“ /var/lib/mysql/mysql.sock”连接到本地MySQL服务器(2) - Could not connect: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 无法通过套接字'/tmp/mysql.sock'(2)错误连接到本地MySQL服务器 - Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) error Mac Terminal / MySQL配置问题| 错误2002(HY000):无法通过套接字'/tmp/mysql.sock'连接到本地MySQL服务器(2) - Mac Terminal/ MySQL configuration issues | ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 尝试了所有事情仍然得到 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 mysql连接错误:无法通过套接字'/var/lib/mysql/mysql.sock'连接到本地MySQL服务器(2)Godaddy Cpanel - mysql connection error: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) Godaddy Cpanel Wordpress中的MYSQL连接问题-无法通过套接字'/var/lib/mysql/mysql.sock'连接到本地MySQL服务器(2) - Issue with MYSQL connection in Wordpress - Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) MySQL服务器崩溃且无法启动-无法通过套接字'/tmp/mysql.sock连接到本地MySQL服务器 - MySQL Server crashes and fails to start - Can't connect to local MySQL server through socket '/tmp/mysql.sock MAMP “Apache 无法启动,因为端口正在使用中。” 和“无法通过 /tmp/mysql.sock 连接到本地 MySQL 服务器 - MAMP “Apache couldn't be started because port is in use.” AND "Can’t connect to local MySQL server through /tmp/mysql.sock
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM