php not connecting to mysql

Discussion in 'Web Design and Development' started by Dunmail, Nov 5, 2010.

  1. Dunmail macrumors regular

    Joined:
    Mar 27, 2009
    Location:
    Skipton, UK
    #1
    I have just got my mac back from a repair centre (airport card) and the php scripts on my local copies of are no longer connecting with the mysql database, I get a 2002 error. For some reason my machine hadn't taken any updates so the repair centre forced the machine to take all of them (a lot apparently) and it would appear that one of them has messed things up.

    I can access the database via the terminal but the php scripts in my web pages would result in the 2002 error stating: ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ .

    I've tried several of the "solutions" on the web but now rather than get an error connecting, there is no output from the PHP script in to the web page whatsoever. :(

    Any hints?
     
  2. elppa macrumors 68040

    elppa

    Joined:
    Nov 26, 2003
    #2
    First you need to undo the damage the “solutions” did. Then you need to change the default_socket location (which is extremely likely to be the actual problem).

    It is looking for /var/lib/mysql/mysql.sock, it should be looking for: /tmp/mysql.sock.

    If you need instructions on how to edit your php.ini file to change the default socket let me know. And certainly if you've never edited a php ini file let me know and I will give you detailed instructions.
     
  3. Dunmail, Nov 6, 2010
    Last edited: Nov 6, 2010

    Dunmail thread starter macrumors regular

    Joined:
    Mar 27, 2009
    Location:
    Skipton, UK
    #3
    Sorted!

    Actually that was one of the solutions :rolleyes: I was a bit tired last night and wasn't thinking things through logically.

    What I hadn't done was to restart the machine rather than just restart the mysql server. Shouldn't have been any different but it was.

    I've set all three variants: PDO; mysqli and mysql to use /tmp/mysql.sock

    Thanks anyway.
     
  4. elppa macrumors 68040

    elppa

    Joined:
    Nov 26, 2003
    #4
    Cool, for future reference you just need to restart Apache Web Server, not the machine.
     
  5. Dunmail thread starter macrumors regular

    Joined:
    Mar 27, 2009
    Location:
    Skipton, UK
    #5
    I did restart Apache, but not every time I made a change so probably missed doing it when I had the correct solution! Like I said, I was a bit tired last night and not my logical self :eek:
     

Share This Page