Can't connect to local MySQL server through socket ...

Problems with the Mac OS X version of XAMPP, questions, comments, and anything related.

Can't connect to local MySQL server through socket ...

Postby bartw » 28. August 2009 21:44

Hi,

I'm getting this after a fresh install from XAMPP. Starting SQL and Apache and running a simpel PHP script which connects to the database and just lists the contents (database and tabels are created, just in case anyone asks ;-) ).

Could not connect: Can't connect to local MySQL server through socket '/var/mysql/mysql.sock'.

This is the PHP script ...

Code: Select all
<?PHP

$link = mysql_connect("localhost","root","");
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db("barts_store");

$query = 'SELECT * FROM producten';
$results = mysql_query($query);

echo "<?xml version=\"1.0\"?>\n";
echo "<producten>\n";

while($line = mysql_fetch_assoc($results)) {
   echo "<item>" . $line["product"] . "</item>\n";
}

echo "</products>\n";

mysql_close($link);

?>
bartw
 
Posts: 3
Joined: 28. August 2009 19:12

Re: Can't connect to local MySQL server through socket ...

Postby bartw » 28. August 2009 22:08

I fixed my own issue in the meantime ...

Thanks to this post http://mattlangtree.com.au/2009-07-05/leopard-mysql_connect-cant-connect-to-local-mysql-server-through-socket-var-mysql-mysql-sock-2.html I was able to locate the location of the socket.

Then it is as simple as going into your phpMyAdmin, going into the variables section, searching for socket and using the location you find there (for my installation that is /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock) to update the /etc/php.ini file (which you might need to create from /etc/php.ini.default).

Search for mysql.deafult_socket, and add the path you found in the previous step. Save and restart Apache.

I seriously do not understand that this is not part of the standard setup of XAMMP, or at least better documented.
bartw
 
Posts: 3
Joined: 28. August 2009 19:12

Re: Can't connect to local MySQL server through socket ...

Postby Wiedmann » 28. August 2009 22:34

I seriously do not understand that this is not part of the standard setup of XAMMP,

Because XAMPP/PHP is (should) not using the file "/etc/php.ini"...

Shure that you are using Apache/PHP from XAMPP?
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Can't connect to local MySQL server through socket ...

Postby skyhook » 17. September 2009 19:42

I spent many days with this "Can't connect to local MySQL server through socket ..." error. FINALLY I fixed it. After reinstalling XAMPP for the third time, I got the localhost to show the correct XAMPP settings. Got phpMyAdmin working too. BUT when trying to access mysql from the terminal I got the dreaded error above.
After much online research, I found that I had a .profile file in my user directory pointing to the correct path:
PATH=$PATH:/Applications/XAMPP/xamppfiles/bin
export PATH
But I was still getting the "Can't connect to local MySQL server through socket ..." error. What I needed to do was to replace the PATH in the .bash_profile file with the above PATH. THe original was pointing to the MAC installed mysql path. This worked ! I now can use the terminal and phpMyAdmin etc. This also fixed an error: .bash mysql no such directory I was getting on my MACBOOK PRO.

Running OS 10.5.8 on mac pro dual quad

Hope this helps anyone else that has made a career out of trying to get XAMPP set up.

wm
skyhook
 
Posts: 1
Joined: 17. September 2009 19:28


Return to XAMPP for macOS

Who is online

Users browsing this forum: No registered users and 11 guests