bluethundr Posted November 12, 2009 Share Posted November 12, 2009 Hi I have php 5.3.0 installed on my snow leopard mac. mysql 5.1 is installed and running. everything is local. I can log into mysql from the command line but for some reason even tho I am feeding my php scripts the correct login and they used to work they can no longer connect to my local mysql install. I could use some help troubleshooting this. Specifically this line used to work: if (!($connection = @ mysql_connect("localhost","user","shhhhh"))) die("Could not connect"); now this script jumps right to the die line. I'm honestly not sure what changed here. help! Quote Link to comment https://forums.phpfreaks.com/topic/181310-solved-php-no-longer-connects/ Share on other sites More sharing options...
trq Posted November 13, 2009 Share Posted November 13, 2009 Try removing the error suppressor and echoing mysql_error to at least attempt to see what the problem is. Quote Link to comment https://forums.phpfreaks.com/topic/181310-solved-php-no-longer-connects/#findComment-956595 Share on other sites More sharing options...
bluethundr Posted November 13, 2009 Author Share Posted November 13, 2009 this is what I saw when I removed the '@' suppressor and ran mysql_error(); Error 2002 : No such file or directory Quote Link to comment https://forums.phpfreaks.com/topic/181310-solved-php-no-longer-connects/#findComment-956664 Share on other sites More sharing options...
bluethundr Posted November 13, 2009 Author Share Posted November 13, 2009 these are the permissions on my my.cnf which lives in /private/etc on the mac mazdayasna:etc bluethundr$ ls -la my.cnf -rw-r--r-- 1 root wheel 10 Nov 10 14:10 my.cnf also I've noticed that it is empty, except for the statement [mysqld] I tried to add the large packets directive in my.cnf max_allowed_packet=32M but then mysql wouldn't launch. so I removed it, and it started launching again. I think this is when php stopped being able to connect. I noticed when I installed mysql on my mac, unlike my linux boxen the my.cnf is curiously empty. Quote Link to comment https://forums.phpfreaks.com/topic/181310-solved-php-no-longer-connects/#findComment-956668 Share on other sites More sharing options...
bluethundr Posted November 17, 2009 Author Share Posted November 17, 2009 Well I just fixed this problem with the help of spox on #php on freenode. The mac install of MySQL does not conform to all the "usual" locations you are used to on a linux install. The most important things you have to change in your php.ini file are where the sock lives. On linux any reference to mysqld.sock in your ini file should point to /var/run/mysqld/mysqld.sock On the mac you need to change those references to /opt/local/var/run/mysql5/mysqld.sock But the most important thing in my case in solving this problem was adding the line mysql.default_socket = /tmp/mysql.sock (which was missing in my ini file) and resetting mysqli.default_socket to mysqli.default_socket = /tmp/mysql.sock. This was the source of the WIN after struggling for a week. THANKS SPOX!!! Quote Link to comment https://forums.phpfreaks.com/topic/181310-solved-php-no-longer-connects/#findComment-959378 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.