This forum is no longer active. Please post your questions to our new community site

Forums MAMPStack

Can't connect to local MySQL server through socket

Subscribe to Can't connect to local MySQL server through socket 3 post(s), 2 voice(s)

 
Avatar bnwpro 2 post(s)

I’m running Mampstack-1.1-0 on OSX 10.5.6 Server. I’m having what seems to be a PHP->MySQL related issue.

When I try to run a PHP script that normally queries a database using PDO, I’m getting the follwoing exception:
Connection failed: SQLSTATEHY000 Can’t connect to local MySQL server through socket ’/tmp/mysql.sock’ (2)

Looking at a phpinfo script (running off of the mampstack apache instance and definitely pointing to the correct php for mampstack), the problem seems to be with php.ini as shown below:

Under “mysql” MySQL Support: (partial)
MYSQL_SOCKET /tmp/mysql.sock

and, under Directive (master/slave):
mysql.default_socket /Applications/mampstack-1.1-0/mysql/tmp/mysql.sock

Shouldn’t the MYSQL_SOCKET be set to ”/Applications/mampstack-1.1-0/mysql/tmp/mysql.sock”? I know that ”/tmp/mysql.sock” is not valid but I’m unsure of how to change MYSQL_SOCKET for php.

I’ve checked the my.cnf file in mampstack-1.1-0/mysql and all sockets are specified as ”/Applications/mampstack-1.1-0/mysql/tmp/mysql.sock”.
Also, the included phpmyadmin works fine and successfully connects to MySQL. I’m having the problem only when querying the database from apache/htdocs using php.

Thanks in advance,
Brendon

 
Avatar bnwpro 2 post(s)

My immediate solution was to create the following symlink:

$ sudo ln -s /Applications/mampstack-1.1-0/mysql/tmp/mysql/mysql.sock /tmp/mysql.sock

That got me connected to the database through php. This may be the boneheaded solution… I’m not sure. The symlink persists across mysql stops-starts so I’m happy.

 
Avatar Beltrán Rueda Administrator 3,714 post(s)

Hi,

You can also try defining the MySQL_UNIX_PORT environment variable to /Applications/mampstack-1.1.-0/mysql/tmp/mysql.sock.

I hope it helps.

Forums MAMPStack