Jump to content

Strange Problem Connecting To Mysql


tc2010

Recommended Posts

I am a bit befuddled here. From CLI, I tested connectivity to a "localhost" MySQL install via php script. It connects with no errors (script is below). I access the same script from a browser, and this error is returned:

 

Connection failure: 2002

Error: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (13)

 

I am unclear why it would work from command-line, but not when called from a browser. Anyone have any advice on this?

 

I don't think it's a firewall issue, but I opened port 3306 nonetheless, and the result is the same. I also made sure the "apache" account has access to "/var/lib/mysql/", and can see "mysql.sock".

 

This is the code in my php test script:

 

<?php

$conn = new mysqli('localhost', 'account', 'password', 'test');

 

if(mysqli_connect_errno()) {

echo "Connection failure: " . mysqli_connect_errno() . "<br />Error: ".mysqli_connect_error();

exit();

}else{

echo "Success";

}

 

?>

 

Thank you.

Link to comment
Share on other sites

Connection failure: 2002

Error: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (13)

 

The (13) is the system error code for why exactly it cannot connect.  If you lookup that error using the perror utility you get:

kicken@linode:~$ /usr/local/mysql/bin/perror 13

OS error code  13:  Permission denied

 

As such, you need to check your permissions again.  The user your server is running as does not have the proper access rights to open that file.

 

Link to comment
Share on other sites

Thanks for the reply, kicken.

 

The web server is an apache one, and runs under the "apache" uid. I assumed the role of "apache", and ran the script from command-line, and had a successful connection to MySQL. I double-checked to be sure that "apache" has access to "mysql.sock" (I navigated to /var/lib/mysql as "apache" user). mysql.sock is world read/write.

 

I'll try moving mysql.sock to tmp, and see if that helps.

 

Thank you for the assistance.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.