Can't connect to MySQL on Mac -- missing mysql.sock file
Asked Answered
E

7

8

I installed MySQL on my Mac OS 10.6 about a week ago, and, after some playing around, got it to work just fine. It integrated with python MySQLdb and I also got Sequel Pro to connect to the database. However, php wouldn't access the server. 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.

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.

I can start the mysql server from Terminal, but it logs me out automatically after a minute:

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):

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

The PHP error is of course similar:

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. There are my.cnf files for the mysql installations that come along with XAMPP. Those also have the default socket listed as '/tmp/mysql.sock', but I had to change them manually.

Any ideas what's going on? Why would modifying the php.ini file have produced a change for Sequel Pro as well?

Ezmeralda answered 26/4, 2011 at 0:45 Comment(2)
Sorry it doesn't answer the question, but I had all sorts of weird Apache, PHP, and MySQL problems on Mac. After spending 3 days trying to fix it, I just reinstalled OS X. I now rely on VMs instead.Perigee
I would use XAMPP, barely any configurationNeutralize
G
20

First of all I suggest you to use homebrew to install any third part libraries or tools on your mac. Have a look to : Link

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.

Glycerin answered 26/4, 2011 at 2:59 Comment(1)
locate mysql | grep sock is finding only /usr/local/Cellar/mysql/5.7.17/include/mysql/mysql/psi/mysql_socket.hBywaters
C
5

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!

Clino answered 2/10, 2014 at 18:4 Comment(1)
Thank you so much. I've been looking for a solution for hours. This one worked pretty well!!!Auctorial
J
4

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!

Jitterbug answered 19/1, 2012 at 1:38 Comment(1)
This worked perfectly for me, the mysql.sock file showed up in /tmp/ folder. thank you! Never would have thought to do that.Pollinosis
P
4

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.

Pitre answered 19/1, 2015 at 15:41 Comment(0)
V
2

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!

Vicechairman answered 5/8, 2011 at 19:30 Comment(0)
P
0

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.

Probate answered 22/6, 2015 at 22:1 Comment(1)
His mysql.sock does not exist in his computer, is what is asking for, is not asking how to put DB_SOCKET into .envGard
S
0

If you have installed mysql through homebrew, simple brew services restart mysql may help.

Synergetic answered 27/1, 2020 at 16:41 Comment(2)
He said in "XAMPP" not in homebrewGard
While searching about the same issue for homebrew, this post appears, so it may be helpful for homebrew users too.Synergetic

© 2022 - 2024 — McMap. All rights reserved.