LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-01-2005, 10:11 AM   #1
oxblood
Member
 
Registered: Jan 2004
Location: Atlanta, GA
Distribution: Slackware 12.2
Posts: 82

Rep: Reputation: 17
PHP5-MySQL Not Connecting Through Socket


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.
 
Old 09-01-2005, 10:37 PM   #2
oxblood
Member
 
Registered: Jan 2004
Location: Atlanta, GA
Distribution: Slackware 12.2
Posts: 82

Original Poster
Rep: Reputation: 17
Anyone?
 
Old 09-02-2005, 02:45 AM   #3
thermite_1033
Member
 
Registered: May 2004
Location: Antwerp, Belgium
Distribution: slackware
Posts: 112

Rep: Reputation: 18
php needs to be able to read every dir in the path of the socket

drwxrwx--- 2 mysql mysql 80 2005-08-24 22:09 ./

should be 755
 
Old 09-02-2005, 07:06 AM   #4
oxblood
Member
 
Registered: Jan 2004
Location: Atlanta, GA
Distribution: Slackware 12.2
Posts: 82

Original Poster
Rep: Reputation: 17
thermite_1033,

Thank you very much with your keen eyes. Sometimes you go through every itty bitty detail and loose the bigger picture. Indeed, the directory permission was the culprit. Again, thank you for your help.
 
Old 09-02-2005, 09:26 AM   #5
thermite_1033
Member
 
Registered: May 2004
Location: Antwerp, Belgium
Distribution: slackware
Posts: 112

Rep: Reputation: 18
i know that's why i always check permisions first and then the remaining possible problems i can think of
 
Old 03-15-2010, 05:53 PM   #6
kkck
LQ Newbie
 
Registered: Mar 2008
Posts: 1

Rep: Reputation: 0
I have the same problem,

But that solution doesn't work for me i don't know whats happening


drwxr-xr-x 12 mysql mysql 4096 Mar 15 18:44 ./
drwxr-xr-x 23 root root 4096 Mar 15 02:28 ../
-rw-rw---- 1 mysql mysql 6 Dec 30 15:00 xxxx.pid
-rw-rw---- 1 mysql mysql 32483 Mar 15 18:44 xxxxxxxx.err
-rw-rw---- 1 mysql mysql 6 Mar 15 18:44 xxxxxxxx.pid
-rw-rw---- 1 mysql mysql 366 Mar 15 02:37 xxxxxxxxxx.log
drwxr-xr-x 2 mysql mysql 4096 Dec 30 14:52 cphulkd/
drwxr-xr-x 2 mysql mysql 4096 Mar 15 02:41 eximstats/
drwxr-xr-x 2 mysql mysql 4096 Dec 30 14:53 horde/
-rw-rw---- 1 mysql mysql 10485760 Mar 15 18:44 ibdata1
-rw-rw---- 1 mysql mysql 5242880 Mar 15 18:44 ib_logfile0
-rw-rw---- 1 mysql mysql 5242880 Dec 30 14:28 ib_logfile1
drwxr-xr-x 2 mysql mysql 4096 Dec 30 14:46 leechprotect/
drwxr-xr-x 2 mysql mysql 4096 Mar 15 01:48 modsec/
drwxr-xr-x 2 mysql mysql 4096 Mar 15 02:33 mysql/
-rw-rw---- 1 mysql mysql 5316365 Mar 15 00:47 mysql-bin.000003
-rw-rw---- 1 mysql mysql 486 Mar 15 00:59 mysql-bin.000004
-rw-rw---- 1 mysql mysql 2427 Mar 15 00:59 mysql-bin.000005
-rw-rw---- 1 mysql mysql 639904 Mar 15 00:59 mysql-bin.000006
-rw-rw---- 1 mysql mysql 13858 Mar 15 00:59 mysql-bin.000007
-rw-rw---- 1 mysql mysql 348 Mar 15 01:01 mysql-bin.000008
-rw-rw---- 1 mysql mysql 9295 Mar 15 01:05 mysql-bin.000009
-rw-rw---- 1 mysql mysql 117 Mar 15 01:07 mysql-bin.000010
-rw-rw---- 1 mysql mysql 872 Mar 15 01:18 mysql-bin.000011
-rw-rw---- 1 mysql mysql 2310 Mar 15 01:22 mysql-bin.000012
-rw-rw---- 1 mysql mysql 117 Mar 15 01:27 mysql-bin.000013
-rw-rw---- 1 mysql mysql 117 Mar 15 01:33 mysql-bin.000014
-rw-rw---- 1 mysql mysql 2427 Mar 15 01:33 mysql-bin.000015
-rw-rw---- 1 mysql mysql 639904 Mar 15 01:33 mysql-bin.000016
-rw-rw---- 1 mysql mysql 13858 Mar 15 01:33 mysql-bin.000017
-rw-rw---- 1 mysql mysql 348 Mar 15 01:34 mysql-bin.000018
-rw-rw---- 1 mysql mysql 117 Mar 15 01:36 mysql-bin.000019
-rw-rw---- 1 mysql mysql 117 Mar 15 01:37 mysql-bin.000020
-rw-rw---- 1 mysql mysql 330 Mar 15 01:39 mysql-bin.000021
-rw-rw---- 1 mysql mysql 13241 Mar 15 01:44 mysql-bin.000022
-rw-rw---- 1 mysql mysql 22697 Mar 15 01:45 mysql-bin.000023
-rw-rw---- 1 mysql mysql 17669 Mar 15 01:45 mysql-bin.000024
-rw-rw---- 1 mysql mysql 55527 Mar 15 01:58 mysql-bin.000025
-rw-rw---- 1 mysql mysql 125 Mar 15 01:58 mysql-bin.000026
-rw-rw---- 1 mysql mysql 4669 Mar 15 02:14 mysql-bin.000027
-rw-rw---- 1 mysql mysql 440 Mar 15 02:19 mysql-bin.000028
-rw-rw---- 1 mysql mysql 1283 Mar 15 02:26 mysql-bin.000029
-rw-rw---- 1 mysql mysql 125 Mar 15 02:37 mysql-bin.000030
-rw-rw---- 1 mysql mysql 6861 Mar 15 03:00 mysql-bin.000031
-rw-rw---- 1 mysql mysql 202520 Mar 15 15:20 mysql-bin.000032
-rw-rw---- 1 mysql mysql 8415 Mar 15 15:50 mysql-bin.000033
-rw-rw---- 1 mysql mysql 511 Mar 15 15:52 mysql-bin.000034
-rw-rw---- 1 mysql mysql 10874 Mar 15 16:20 mysql-bin.000035
-rw-rw---- 1 mysql mysql 31800 Mar 15 17:51 mysql-bin.000036
-rw-rw---- 1 mysql mysql 15435 Mar 15 18:44 mysql-bin.000037
-rw-rw---- 1 mysql mysql 106 Mar 15 18:44 mysql-bin.000038
-rw-rw---- 1 mysql mysql 684 Mar 15 18:44 mysql-bin.index
srwxrwxrwx 1 mysql mysql 0 Mar 15 18:44 mysql.sock=
drwxr-xr-x 2 mysql mysql 4096 Mar 15 01:02 xxxxxxx_xxxxxxx/
drwxr-xr-x 2 mysql mysql 4096 Dec 30 14:53 xxxxxxxxx/
drwxr-xr-x 2 mysql mysql 4096 Mar 15 00:59 xxxxxxxx/
drwxr-xr-x 2 mysql mysql 4096 Feb 26 2009 xxxxxxxxx/


another sugestion?

Last edited by kkck; 03-15-2010 at 05:55 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. NoviceW Linux - Networking 17 09-17-2014 02:13 PM
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock welery Linux - Software 19 03-06-2014 07:19 AM
ERROR 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. suziecorbett Linux - Software 8 10-09-2008 01:52 AM
mysql error Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. Dannux Linux - Software 3 03-24-2006 08:44 AM
Converting php5 socket functions to php3 socket functions mrobertson Programming 0 06-23-2005 09:11 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration