[SOLVED] Connection Problem in linux

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
dbudde
Forum Commoner
Posts: 25
Joined: Mon Dec 01, 2003 4:02 pm
Location: Chicago, IL

[SOLVED] Connection Problem in linux

Post by dbudde »

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
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

Can you connect to MySQL on the command line?

Are you positive MySQL is running?

I would say your user/pass might be wrong, but that would give you a different warning/error.

What distro are you running? Did you install binaries of MySQL, php and Apache or did you compile them from source?
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

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
dbudde
Forum Commoner
Posts: 25
Joined: Mon Dec 01, 2003 4:02 pm
Location: Chicago, IL

Thanks for the speedy replies

Post by dbudde »

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.
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

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...
User avatar
mrvanjohnson
Forum Contributor
Posts: 137
Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA

Post by mrvanjohnson »

Run this script real fast

Code: Select all

<?php
phpinfo () ;
?>
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
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

He would of had to compile from source and old version of php4 for MySQL not be enabled.
dbudde
Forum Commoner
Posts: 25
Joined: Mon Dec 01, 2003 4:02 pm
Location: Chicago, IL

I got it working

Post by dbudde »

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.
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

NP ;)
Post Reply