[SOLVED] Connection Problem in linux
Moderator: General Moderators
[SOLVED] Connection Problem in linux
Ok, I have not been able to figure out why my php/apache server is not able to connect to my mysql server and they are all on the same linux box. I checked /etc/services and the mysql server is on port 3306 and I set that to the default port in php.ini, and "YES" both apache and mysql are up and running. Below is the code that I use straight from php.net.
<?php
$link = mysql_connect("localhost", "mysql_user", "mysql_password")
or die("Could not connect: " . mysql_error());
print ("Connected successfully");
mysql_close($link);
?>
The error im getting on the page is,
Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111) in /srv/www/htdocs/login.php on line 68
Could not connect: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)
Please give me a hand. This is only my 2nd or 3rd venture into setting up these 2 servers to play together and I could really use some help.
Thanks, Daniel
<?php
$link = mysql_connect("localhost", "mysql_user", "mysql_password")
or die("Could not connect: " . mysql_error());
print ("Connected successfully");
mysql_close($link);
?>
The error im getting on the page is,
Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111) in /srv/www/htdocs/login.php on line 68
Could not connect: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)
Please give me a hand. This is only my 2nd or 3rd venture into setting up these 2 servers to play together and I could really use some help.
Thanks, Daniel
- Pyrite
- Forum Regular
- Posts: 769
- Joined: Tue Sep 23, 2003 11:07 pm
- Location: The Republic of Texas
- Contact:
The port etc doesn't matter since you're setup is trying to connect to MySQL through sockets. A connection warning like that means that either the mysql server isn't up and running or the mysqld doens't have the right permission to the socket file or is connecting to the wrong one.
Have a look at:
http://www.mysql.com/doc/en/Can_not_con ... erver.html
Might make a symlink to your socket file.
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
Also might want to give your socket some permissions like:
chmod 755 /var/lib/mysql/mysql.sock
Have a look at:
http://www.mysql.com/doc/en/Can_not_con ... erver.html
Might make a symlink to your socket file.
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
Also might want to give your socket some permissions like:
chmod 755 /var/lib/mysql/mysql.sock
Thanks for the speedy replies
Yes, I can attach to MySql from the command prompt and yes it is on. Yes, my php/apache server is up and running or I would not reach my php pages.
I will try your answers about the sockets, but that sounds to be it. Thank you, I will drop a line later as to if it helped or did not help.
I will try your answers about the sockets, but that sounds to be it. Thank you, I will drop a line later as to if it helped or did not help.
- Pyrite
- Forum Regular
- Posts: 769
- Joined: Tue Sep 23, 2003 11:07 pm
- Location: The Republic of Texas
- Contact:
ps aux | grep mysql
And if you see mysqld in the process list, then its running. Otherwise. Sometimes safe_mysqld won't tell you it can't start MySQL. But then you'll need to find out how you're starting it and what youre doing wrong. Either mysqld is a daemon or is handled by inetd. So if you were starting the mysql as a daemon in an init script suppose and you were passing it the wrong socket option or something...
And if you see mysqld in the process list, then its running. Otherwise. Sometimes safe_mysqld won't tell you it can't start MySQL. But then you'll need to find out how you're starting it and what youre doing wrong. Either mysqld is a daemon or is handled by inetd. So if you were starting the mysql as a daemon in an init script suppose and you were passing it the wrong socket option or something...
- mrvanjohnson
- Forum Contributor
- Posts: 137
- Joined: Wed May 28, 2003 11:38 am
- Location: San Diego, CA
Run this script real fast
Then search on that page for the MySQL section and make sure it says "Enabled" next to it. Just to make sure you have PHP compiled with MySQL support
Code: Select all
<?php
phpinfo () ;
?>I got it working
Pyrite, thanks for your help. There were two copies of mysql.sock for some reason in two different directories. The php server was looking at the wrong one. I changed it in my php.ini file and now it seems to running with no problems, thanks for you help.