Problem with MySQL Installation on Mac

I’m using Mac OS 10.6.4. I have installed MySQL. I can access it via the Terminal and do all the normal things, create databases, create tables, etc. It all works just as I would expect it to.

But, when I try to connect via a web script it won’t connect.

I created a very simple little php script to test the connection:

<?php

echo mysql_connect (‘localhost’, ‘root’, ‘mypassword’);

?>

When I load this page I get the following error:

Warning: mysql_connect() [function.mysql-connect]: [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in /Users/stevewilkison/Sites/connect.php on line 3

Warning: mysql_connect() [function.mysql-connect]: No such file or directory in /Users/stevewilkison/Sites/connect.php on line 3

I don’t understand why I am able to access the MySQL via the Terminal but not via a php script. I’m using the same user (root) and password in the Terminal that I’m using in the php script. I’ve done this before and never had any problems.

Any help would be greatly appreciated, as this is driving me crazy!

Thanks very much.

It might be your socket,

http://us3.php.net/manual/en/mysql.configuration.php#ini.mysql.default-socket (See the 2 comments at the bottom)

Which suggests:
If necessary, you can edit your php.ini to change it to /tmp/mysql.sock.

php.ini


; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
; http://php.net/mysql.default-socket
mysql.default_socket =

Hi, I have the same issue, dont get the same error, but think that may be as I dont have error reporting. but I get cannot connect to db I am using the following:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=“http://www.w3.org/1999/xhtml”>
<head>
<title>???</title>
<meta http-equiv=“content-type”
cotent=“text/html; charset=iso-8859-1” />
</head>
<body>
<?php
// Define how to display/errors
ini_set(“display/errors”, “1”);
error_reporting(E_ALL);

$hostname = "localhost";
$username = "pee_wee";
$password = "let_me_in";
$dbh = mysql_connect($hostname, $username , $password) or die("Unable to connect to MySQL" . mysql_error( ));
	print "Connected to MySQL&lt;br&gt;";
// you're going to do lots more here soon
mysql_close($dbh);

$dbname = 'first_test';

mysql_select_db($dbname);
?>
</body>
</html>

Been trawling the web for a week now trying to find an answer, used the 3rd edition version as my guide for install. purchase years ago but only now have the need to extern my web site so trying to get this working on my mac to trail out some ideas.

Many thanks, that did it, been all over the web and waster hours of time.

Star, many thanks. Now on with the rest of the book

Rgds, LostOZ1 from a hotel room in Tallinn not much else to do here :slight_smile: