Board index   FAQ   Search  
Register  Login
Board index PHP PHP Installation

PHP5-MySQL Not Connecting Through Socket

Forum for you who has PHP installation issues

Moderators: macek, egami, gesf

PHP5-MySQL Not Connecting Through Socket

Postby oxblood » Thu Sep 01, 2005 8:07 am

Hi,

I am running PHP 5.0.4 and MySQL 4.1.3a. (+Apache 2.0.54, Slackware 0.1, kernel 2.6.11.3) When I run a PHP script that attempts to connect to MySQL I get the following error:

Database ERROR:Can't connect to local MySQL server through socket
'/usr/local/mysql/tmp/mysql.sock' (13)

I have placed my socket file on such location when I was configuring MySQL and PHP was compiled with --with-mysql-sock=/usr/local/mysql/tmp/mysql.sock (and even with /usr/local/mysql/tmp). I even edited my php.ini /usr/local/php/lib/php.ini, I have installed PHP with --prefix=/usr/local/php) and modified variable:

mysql.default_socket = "/usr/local/mysql/tmp/mysql.sock"

It still refuses to connect through the socket! I have also run a simple mysql_connect() script to see if the intended script was the culprit but again, it could not connect to MySQL.

phpinfo() indicates the following:

MYSQL_SOCKET /usr/local/mysql/tmp/mysql.sock
MYSQL_INCLUDE -I/usr/local/mysql/include/mysql
MYSQL_LIBS -L/usr/local/mysql/lib/mysql -lmysqlclient

And for directives:
mysql.default_port no value no value
mysql.default_socket /usr/local/mysql/tmp/mysql.sock /usr/local/mysql/tmp/mysql.sock

That being said, I "CAN" connect to the database via "127.0.0.1" through TCP/IP but not through Unix Socket file. The permissions on mysql.sock is:

ls -la /usr/local/mysql/tmp/
total 0
drwxrwx--- 2 mysql mysql 80 2005-08-24 22:09 ./
drwxr-xr-x 13 root mysql 328 2005-08-22 20:03 ../
srwxrwxrwx 1 mysql mysql 0 2005-08-24 22:09 mysql.sock=

I do have /etc/my.cnf (644 permission). A "bind-address" directive has been set to "127.0.0.0" by default. I changed to "127.0.0.1" and even commented out, but no luck. /etc/my.cnf's socket file path and name in both [client] and [mysqld] section are the same and have been set accordingly (phpinfo() verifies that).

As far as MySQL user and database, the followings is the result of commandline connection:

mysql -h127.0.0.1 -D dbname -u<username> -p # Rejected, obviously
mysql -h<publicIP> -D dbname -u<username> -p # Rejected
mysql -hlocalhost -D dbname -u<username> -p # Accepted as I expected

So I don't understand why I can connect with host "localhost" in commandline or other "non-php" programs but not with PHP!! I have disabled networking connection to MySQL ("skip networking") in /etc/my.cfg as I run the necessary programs only on one system. All MySQL users (root and what not) only have privileges to "localhost" and nothing else.

I do have the following entries in my /etc/hosts:

127.0.0.1 localhost
127.0.0.1 myhostname.myhostname myhostname

I can ping my localhost, designated LAN IP, and 127.0.0.1 just fine by the way.

No, I do not run any DNS server on the machine that I am having this problem. The whole point of using locahost Vs. 127.0.0.1 is to avoid the overhead of TCP by using Unix socket file.

Again, I can connect to DB through other programs (non-php) or via commandline and even TCP but not through Unix socket file!! And this does not only happen with one PHP script attempting to connect or query the database but with even the simplest snippet of code.


[OH NO!] After some going back and forth and restarting MySQL, for some reason now my PHP scripts keep loosing connection during query through EVEN 127.0.0.1 [Database ERROR: Lost connection to MySQL server during query].

My last resort was to downgrad from PHP 5 to PHP 4.4.0 but I still suffer from the same error messages (localhost connection cannot connect through socket and 127.0.0.1 keeps loosing connection during query). NOTE, that this happens with every PHP scripts that attempts to access MySQL database.

I don't know, maybe I need some serious MySQL+PHP guru assistance.
oxblood
New php-forum User
New php-forum User
 
Posts: 3
Joined: Thu Sep 01, 2005 8:06 am

Postby oxblood » Thu Sep 01, 2005 7:36 pm

Anyone?
oxblood
New php-forum User
New php-forum User
 
Posts: 3
Joined: Thu Sep 01, 2005 8:06 am

Postby oxblood » Fri Sep 02, 2005 4:34 am

Ok, someone mentioned that I did not have an appropriate permission to access mysql.sock directory. Guess what? He was right on the spot. So for whomever who reads this, the solution proposed is to `chmod 755 /usr/local/mysql/tmp'

Thanks to that individual who assisted me on this.
oxblood
New php-forum User
New php-forum User
 
Posts: 3
Joined: Thu Sep 01, 2005 8:06 am


Return to PHP Installation

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.