Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Neb Cross

macrumors newbie
Original poster
Oct 24, 2008
9
0
Hello Everyone,

I am running OS X version 10.5.6 and MySQL version 5.0.67

I have enabled the inbuilt PHP and webserver which was pre-installed on my MAC. I did this using
http://foundationphp.com/tutorials/php_leopard.php
I can run basic PHP code, but i can not connect to MySQL through PHP.
The code i use to connect to MySQL is:
Code:
<html>
<body>
<?php
mysql_connect("localhost", "<username>", "<password>") or die(mysql_error());
echo "Connected to MySQL<br />";
?>
</body>
</html>
However when i run this i get the following error on the web page:
Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2) in /Library/WebServer/Documents/examples/testconnection.php on line 4
Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2)

I would really appreciate any help :)
Thanks in Advance and Regards,
-Neb
 
This is why so many people end up just installing MAMP. These things can get annoying quick. Is the sock file where it's pointing at? I had a similar issue once and created a symbolic link to make sure it was point at the actual sock file. Also, were you following any particular MySQL setup guide?
 
Hi angelwatt,

Thanks for you reply. Honestly, i don't know if the sock file is where it's pointing at. Please could you give me details of how to find this out?

Regarding mysql, i installed it a few months ago. So i wouldn't be able to tell you if i was following a set up guide, i cant remember. I do know that mysql does work. I can connect to it through the terminal. I have set up databases, tables and so on.

Regards,
-Neb
 
Thanks for you reply. Honestly, i don't know if the sock file is where it's pointing at. Please could you give me details of how to find this out?

Simply by going to that folder location in either Finder or Terminal Unless you have Finder set to show hidden files you won't be able to get there in the normal fashion, but can (while on Finder) hit cmd+shift+g, which will bring up a prompt asking what folder to head to. Enter in /var/mysql and hit enter. It'll take you to the folder and you can look and see if the mysql.sock file is in there.

If it's not there you'll want to find where it's at. You can use Finder to search out system files. Once found we can create a symbolic link for the sock. If you already have the folder /var/mysql/ then skip the first line below, but go along with the rest.

Code:
sudo mkdir /var/mysql
sudo ln -s /path/to/actual/mysql.sock /var/mysql/mysql.sock
sudo chown _mysql /var/mysql/mysql.sock
sudo chmod 777 /var/mysql/mysql.sock
(adapted from: http://andreys.info/node/273)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.