Can't connect to MySQL on Mac — missing mysql.sock file

爷,独闯天下 提交于 2019-11-29 02:12:05

First of all I suggest you to use homebrew to install any third part libraries or tools on your mac. Have a look to : 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.

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.

Hope this help.

I was getting some similar error and ended up here. I am using OSX 10.9.5. This solved my problems (hope it helps someone).

1) sudo mkdir /var/mysql

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

Thanks!

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!

The answer turned out to be simply install the MySQLStartupItem.pkg that comes with the dmg file and restart the system. This starts up the daemons upon startup (which I hoped would be optional).

Magically, my /tmp/mysql.sock file appeared and all is well!

I was also getting this error on a fresh install of 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. Upon opening the file in an editor I discovered that the socket file was pointing to:

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

I updated Navicat's Advanced properties/ Use socket file to the path above and bingo.

Hope this helps someone.

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. I am running Mac OS X. And I decided to remove Zend from my system because it was being a pain in my butt.

Upon removing Zend, since both were using the same DB and Zend had it my system went crazy. Uninstalling and reinstalling XAMPP didn't help. 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. The reason being is that mysql still kept trying to look for the Zend mysql path and it was failing.

So I used locate to find it. 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". So I just renamed the file to my.cnf.old and tried to launch MySQL again. 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. In my config file socket was in line 21 and the path was
"/Applications/AMPPS/var/mysql.sock"

In Ampps application click on MySql tab and then click on configuration button.

You can also find the config file in "/Applications/AMPPS/mysql/etc" folder

So simply I added
'unix_socket' => '/Applications/AMPPS/var/mysql.sock',
to my database.php in mysql array and it's worked for me.
After host line. I have tested with localhost and 127.0.0.1 and both worked
Hopefully it's working for you too.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!