Reputation: 722
This is my config file:
$mysql_hostname = "localhost";
$mysql_user = "xyz";
$mysql_password = "abc";
$mysql_database = "mno";
$IT = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Opps some thing went wrong");
mysql_select_db($mysql_database, $IT) or die("Opps some thing went wrong");
Here is the warning that I get from it:
Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/content/03/10531303/html/iqamah.org/config.php on line 13
How can I fix this?
Upvotes: 4
Views: 31455
Reputation: 1
< Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'
After reading some good advice from here. mine worked out for me. i tried removing the "localhost" and add 127.0.0.1 and it worked like magic vouch everyone contributed here
Upvotes: -3
Reputation: 71
I had exactly the same issue
Hope that helps anyone having the same issue. Especially when the log folder didn't exist to troubleshoot.
Upvotes: 1
Reputation: 13967
First check if your database is really listening; do this by calling
netstat -a
You should see something like this
TCP 0.0.0.0:3306 MyComputer:0 LISTEN
If you don't seen a listening process on port 3306 your database is not (properly) started or uses another port. Check your environment carefully. If it's a WAMP/LAMP system you can check your admin pages for the phpinfo()
section (mysqli section)
If your port differs from the standard port try adding the appropriate port, e.g.
$link = mysql_connect('example.com:3331', 'mysql_user', 'mysql_password');
Hope this helps.
Upvotes: 0
Reputation: 331
Please specify the system you're running on. If credentials are ok, this is probably a problem with mysql server. If you're on linux, check if this line returns something on the console. If not, your server is not running:
# netstat -apn | grep mysql
You can also try to connect to mysql here too, so that you check your credentials are ok:
# mysql -h localhost -u user database
If you're on windows, just check if the service is running:
services.msc
msyql
service is running.Upvotes: 3
Reputation: 1056
If you can't connect the database it means that somewhere in the execution process is a problem. Revise your hostname, user, password and database name. Then ensure if the database is really on your server with user data you have written to your code - log in with terminal or something like this...
But on line 13
means, that you have to search problem on line 13. Check this line.
Upvotes: 0
Reputation: 700
The error comes only when connection parameters are wrong, Make sure following credentials are correct
$mysql_hostname = "localhost";
$mysql_user = "xyz";
$mysql_password = "abc";
Upvotes: 0