Breaking News
Home / Web / PHP / PHP Issues / Warning: mysql_connect(): [2002] No such file or directory

Warning: mysql_connect(): [2002] No such file or directory

Issue

Warning: mysql_connect(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in /Users/Mvohra/Sites/projects/webservices/apps/functions.php on line 8

Warning: mysql_connect(): No such file or directory in /Users/Mvohra/Sites/projects/webservices/apps/functions.php on line 8
Could not connect: No such file or directorymymac:admin

Diagnosis

When trying to connect to mysql database using PHP, it not able to connect to mysql. The php connect function using the mysql sock file descriptor to connect. At times the location of the sock file is different. You can specific the location of sock file as the input to the connect function

Solution

Find out the sock file location if this is at different location then the default.

To see the PHP configuration, you can watch the output of phpinfo.
The MySQL Database can be administrated with phpMyAdmin.
To connect to the MySQL Server from your own scripts use the following connection parameters:

Example:

$link = mysql_connect(‘localhost’, ‘root’, ‘root’); // use default sock path.

or you can connect using an UNIX Socket located at location:

/Applications/MAMP/tmp/mysql/mysql.sock

Example:

$link = mysql_connect(
‘:/Applications/MAMP/tmp/mysql/mysql.sock’,
‘root’,
‘root’
);  [pb_builder]

Check Also

PhpMotion fails to generate Captcha Image

Issue I just installed PhpMotion v3.5 and when I go to the register page, the …

Advertisment ad adsense adlogger