LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 10-21-2004, 03:33 AM   #1
ldp
Member
 
Registered: Apr 2004
Location: Belgium Antwerpen
Distribution: slackware - knoppix
Posts: 141

Rep: Reputation: 18
mysql - php socket error.


Problem with mysql db being contacted from a php file.
I try to connect to a mysql db from a php script via the following code:

$link = mysql_connect("localhost", "ldp", "j0sk3");
if (!$link) {
die('Could not connect: ' . mysql_error());
}

The code is correct because I used it in other phpscripts and on another sytem.

And get this error:
Could not connect: Can't connect to local MySQL server through socket '/var/run/mysql/mysql.sock' (2)

This is clear to me that he's looking for the mysql.sock file in the mentionned directory.
But the problem is that my mysql.sock file is in: /tmp/mysql.sock
I can connect to mysql with the /usr/local/mysql/bin/mysql -u .... etc etc without any problem and manipulate the databases.

But my question is thus: why is the php script looking for a socket in another directory??? And how can I force it to look in the /tmp directory???

I compiled the apache, mysql and php myself and I have done this before on my previous system so I think that I did that part correctly.
I put all of it in /usr/local/.... with the --prefix option

Last edited by ldp; 10-21-2004 at 09:20 AM.
 
Old 10-21-2004, 03:41 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,215
Blog Entries: 1

Rep: Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067
Open my.cnf and/or php.ini and change the directory of mysql.sock to the correct location.
Hope that helps.
 
Old 10-21-2004, 07:02 AM   #3
ldp
Member
 
Registered: Apr 2004
Location: Belgium Antwerpen
Distribution: slackware - knoppix
Posts: 141

Original Poster
Rep: Reputation: 18
in /usr/local/php5/lib/ I modified php.ini the following:
mysql.default_socket = "/tmp/mysql.sock"
But that don't help after restart of apache and mysql and php.

Thus looking for my.cnf with find / my.cnf but nothing found???
Not even with "find / my.cnf"

I installed it from a source: mysql-4.1.4a-gamma.tar.gz

In the system.php file I see this for mysql:

Client API version 4.0.20 altough I have 4.1.4 ???
MYSQL_SOCKET /var/run/mysql/mysql.sock
mysql.default_socket /tmp/mysql.sock /tmp/mysql.sock => looks a little contradictory to me but this is where the socket actually is.

 
Old 10-21-2004, 07:17 AM   #4
ldp
Member
 
Registered: Apr 2004
Location: Belgium Antwerpen
Distribution: slackware - knoppix
Posts: 141

Original Poster
Rep: Reputation: 18
and this is strange to me:

lieven@cthulhu:~/src$ netstat -l | grep mysql
unix 2 [ ACC ] STREAM LISTENING 2805 /tmp/mysql.sock

While mysql has to be listening on 3306 by default right?
 
Old 10-21-2004, 07:57 AM   #5
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,215
Blog Entries: 1

Rep: Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067
If you don't have a my.cnf file, look for my-small.cnf, my-medium.cnf and so on, in the support-files subdirectory of mysql (if you installed it from binary), or in the share subdir (if installed from source), rename it to my.cnf, add the location of socket and put it in /etc.
mysqld must in fact listen to port 3306, to verify this run:
Quote:
netstat -tan|grep 3306
 
Old 10-21-2004, 08:46 AM   #6
ldp
Member
 
Registered: Apr 2004
Location: Belgium Antwerpen
Distribution: slackware - knoppix
Posts: 141

Original Poster
Rep: Reputation: 18
Hi,

Yes, in fact, I took the old my.cnf file from my previous installation and adapted it and after a few errors while trying to start the service, it works ok now. (I mounted the drive from my old pc which died some weeks ago)


But the problem in php has changed a little now:

Warning: mysql_connect() [function.mysql-connect]: Client does not support authentication protocol requested by server; consider upgrading MySQL client in /usr/local/apache2/htdocs/php/contact.php on line 11
Could not connect: Client does not support authentication protocol requested by server; consider upgrading MySQL client

Does this really mean that I have to download and install a new client for mysql?? I've never had this before when I installed it from source.

I didn't know that the client was not included with the server?

Thanks already for the answers.
Lieven
 
Old 10-21-2004, 09:07 AM   #7
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,215
Blog Entries: 1

Rep: Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067
I saw now the page you posted with phpinfo() and notice that you've installed php using:
Quote:
./configure --with-mysql --other-options...
Use --with-mysql=/path/to/mysql (point to the dir you installed mysql) to make sure it uses the recent client 4.1.4 and not 4.0.20. The client is included in the binary/source distribution.
Also edit your first post and remove the link to phpinfo as it's not good to advertise your system settings
 
Old 10-21-2004, 09:54 AM   #8
ldp
Member
 
Registered: Apr 2004
Location: Belgium Antwerpen
Distribution: slackware - knoppix
Posts: 141

Original Poster
Rep: Reputation: 18
Right, it's just a testing machine but anyway, I removed the link...

So if I understand correclty, I need to recompile and configure the php.
It probably used the path to the old mysql installation.
No way to adapt this in some conf file to use the correct client?

regards,
Lieven

Last edited by ldp; 10-21-2004 at 09:56 AM.
 
Old 10-21-2004, 10:15 AM   #9
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,215
Blog Entries: 1

Rep: Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067Reputation: 2067
Quote:
consider upgrading MySQL client in /usr/local/apache2/htdocs/php/contact.php on line 11
Check contact.php to see if you can do this from within your code.
Another way to do this is to remove (or better rename) the old mysql and create a symlink to the new one.
 
Old 10-22-2004, 04:40 AM   #10
ldp
Member
 
Registered: Apr 2004
Location: Belgium Antwerpen
Distribution: slackware - knoppix
Posts: 141

Original Poster
Rep: Reputation: 18
Thanks for your help. I did a reconfigure with the correct path to the new mysql installation and it works fine now.
rgds,
Lieven
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 03:13 PM
error: Can't connect to local MySQL server through socket J0sep Red Hat 20 07-13-2011 10:32 AM
ERROR 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. suziecorbett Linux - Software 8 10-09-2008 02:52 AM
mysql error Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. Dannux Linux - Software 3 03-24-2006 09:44 AM
Mysql socket error 3p0ch Linux - Networking 4 01-14-2005 08:38 AM

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

All times are GMT -5. The time now is 03:11 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