Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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?

like image 524
tchaymore Avatar asked Apr 26 '11 00:04

tchaymore


People also ask

Why MySQL sock is missing?

mysqld. sock is created by the mysql daemon on start, and it is removed (or, becomes un-connectable) if this daemon stops. This message is given by some client process, trying to connect your mysqld on this socket without success. Its most likely reason is that the mysqld doesn't run.

Where is my MySQL sock file?

The MySQL server's socket file is named mysqld. sock and on Ubuntu systems it's usually stored in the /var/run/mysqld/ directory. This file is created by the MySQL service automatically.

Where is MySQL sock OSX?

sock , but on my Mac (Mac OS X 10.5) the socket is really located at /private/tmp/mysql. sock .


1 Answers

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.

like image 178
Riba Avatar answered Sep 29 '22 18:09

Riba