I'm getting errors whenever I try to connect locally to mySQL on Mac OS Snow Leopard 10.6.4. I'm running mySQL 5.1.46. I can log in using the console. I'm running PHP 5.3.2 and my phpinfo()
page is working fine. So I've got PHP running, I can log into the mySQL server using both the console and Sequel Pro.
So I suspected that it was a socket issue. In my /etc directory, I don't have php.ini, I have php.ini.default. So I go in there, and every place I see "default_socket" I change it from:
/var/mysql/mysql.sock
to:
/tmp/mysql.sock
I see it in the following locations:
pdo_mysql.default_socket=/tmp/mysql.sock
mysql.default_socket = /tmp/mysql.sock
mysqli.default_socket = /tmp/mysql.sock
And when I go to connect to phpMyAdmin, I get the following error: Cannot start session without errors, please check errors given in your PHP and/or webserver log file and configure your PHP installation properly.
And when I look in my phpinfo()
file, I get the following under mySQL:
mysql.default_socket /var/mysql/mysql.sock /var/mysql/mysql.sock
I restart Apache... heck, I restart the whole computer. Still, nothing. I know mySQL is working, I know PHP is working, but I can't get them talking.
Any help?
PHP should be looking for a php.ini file (and not php.ini.default) to load, so try renaming php.ini.default to php.ini. See Install Apache/PHP/MySQL on Snow Leopard.
If you don't want to muck about with config settings for either mysql or php, then set up this hack:
This creates an alias in the location that PHP is looking for that connects to the real mysql.sock.
Source: http://www.procata.com/blog/archives/2007/10/28/working-with-php-5-in-mac-os-x-105/
Simply creating the /etc/my.cnf file with contents and creating the directory, per Vikash's recommendation, did not solve the problem. mysql.sock still was living in /tmp, even after doing this and restarting the machine. I manually moved the file from /tmp to /var/mysql, and then the error resolved. I had a feeling, though, that upon restart the problem would resurface, and it did. This time the error was slightly different - connection denied. I found that a new socket had been opened in /tmp and the old one was still there in /var/mysql; the code was trying to use the old one and getting denied access. So I used Sid's hack with the symlink and that fixed the problem. I'm sure when I restart, this fix will still work. However, I'd love to know what is causing the system to open new sockets in /tmp instead of the configured /var/mysql.
I did the following to resolve the issue (Mac OS x) -
1.) First go to your apache webroot (path available from /etc/apache2/httpd.conf -> DocumentRoot). For me it was /Library/WebServer/Documents/
1.1) Create a showphpconfig.php at that location
2.) Go and visit this file in your browser : http://127.0.0.1/showphpconfig.php
This will show you what configuration file your apache server is using
For me it was using
/private/etc/php.ini
I also saw that php was using the mysql sock file from
/var/mysql/mysql.sock
3.) I made a copy of the php.ini file. Open it and find all the lines which have mysql.sock.
copy those lines and create a new entry, like below -
;pdo_mysql.default_socket=/var/mysql/mysql.sock
pdo_mysql.default_socket=/tmp/mysql.sock
IMP the ";" in front of the first line, that is commenting out the first line
There should be about 4 such lines
Now you have told php, that the mysql socket file is actually present in the /tmp folder
4.) restart your apache server -
apachectl restart
And you should see the wordpress configuration screen
Try just doing a symlink. For my XAMPP installation this worked:
It does not have to be a problem related to sockets. Try connecting to MySQL from a simple PHP script:
For your PHP.ini path, look in
phpinfo();
for "Loaded Configuration File". It does not have to be located in/etc/php.ini.default