MySQL connection not working: 2002 No such file or directory
P粉422227023
P粉422227023 2024-02-25 14:08:33
0
2
381

I'm trying to set up WordPress. I have Apache and MySQL running and the accounts and databases are set up. I try to establish a simple connection:

<?php
    $conn = mysql_connect('localhost', 'USER', 'PASSWORD');
    if(!$conn) {
        echo 'Error: ' . mysql_errno() . ' - ' . mysql_error();
    }
?>

I always get this:

Error: 2002 - No such file or Table of contents

What file or directory is it talking about?

I'm using OS X Snow Leopard, using the built-in Apache. I installed MySQL using x86_64 dmg.

Update: I discovered that the socket is located at /tmp/mysql.sock, so in php.ini I replaced all occurrences of the wrong path with that.

P粉422227023
P粉422227023

reply all(2)
P粉946336138

I had a similar problem and was able to resolve my mysql issue by using 127.0.0.1 instead of localhost.

This probably means something is wrong with my hosting setup, but I need this quick fix right now.

P粉466909449

If you are using Linux: The path to the mysql.sock file is wrong. This is usually because you are using (LAMPP) XAMPP and it is not in /tmp/mysql.sock

Open the php.ini file and find this line:

mysql.default_socket

Then do it

mysql.default_socket = /path/to/mysql.sock
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!