php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16768 mysql_connect("localhost", ...) doesn't connect to localhost!
Submitted: 2002-04-23 15:50 UTC Modified: 2002-04-25 17:23 UTC
Votes:5
Avg. Score:4.6 ± 0.8
Reproduced:5 of 5 (100.0%)
Same Version:4 (80.0%)
Same OS:2 (40.0%)
From: jr-php at quo dot to Assigned:
Status: Closed Package: MySQL related
PHP Version: 4.2.0 OS: Red Hat Linux 7.2
Private report: No CVE-ID: None
 [2002-04-23 15:50 UTC] jr-php at quo dot to
After upgrading from PHP 4.1.2 to PHP 4.2.0, MySQL connections fail with this error:

Warning: Access denied for user: 'username@my.fully.qualified.name' 

Apparently, it is trying to connect to 'my.fully.qualified.name' instead of 'localhost' as before. This seems wrong because my mysql_connect() call uses 'localhost' as the host name:

mysql_connect("localhost", "username", "password");

I can work around this by changing all my MySQL grants from 'username'@'localhost' to 'username'@'my.fully.qualified.name', but that seems unnecessary; this should be fixed in PHP.

BTW, I've used the same above mysql_connect() call since the PHP 3.x days and it's always worked fine, until now.


My PHP configure line:
./configure --with-apache=../apache_1.3.24 --enable-track-vars \
  --with-mysql --with-zlib --with-gd

All PHP configuration settings are defaults. (i.e. php.ini = php.ini-dist)

Apache version is 1.3.24. MySQL version is 3.23.49a.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-23 17:25 UTC] jr-php at quo dot to
Hmm, I tested again and now I'm getting this slightly different message:

Warning: Host 'my.fully.qualified.name' is not allowed to connect to this MySQL server

Also, I found these calls result in the same error message:

mysql_connect("127.0.0.1", "username", "password");
mysql_connect(":/var/lib/mysql/mysql.sock", "username", "password");

This can't be the correct behavior. When I connect to localhost, MySQL should "see" the PHP connection as being from localhost, NOT my machine's fully-qualified DNS name. This is what happens when I use the command-line "mysql" program, or any prior version of PHP (3.x - 4.1.2).

This is a critical problem because it breaks all of my existing PHP scripts that use MySQL. I'm reluctant to start playing around with my MySQL permissions tables, because if/when this bug is addressed, I'd have to put everything back. So for now, I'm back to 4.1.2.
 [2002-04-24 13:45 UTC] jr-php at quo dot to
As others have stated on the dev list, the problem seems to be that PHP 4.2.0 is trying to connect using TCP instead of using the UNIX socket. I can confirm that this is what's happening on my end too. With PHP 4.1.2, tcpdump shows no TCP traffic and everything works correctly. With PHP 4.2.0, tcpdump shows connections to the MySQL port (3306) and it doesn't work.

In both PHP versions, MYSQL_SOCKET is set the same way according to phpinfo(): /var/lib/mysql/mysql.sock, which is correct for my system. And both PHP versions show the same configure output:

checking for MySQL support... yes
checking for MySQL UNIX socket... /var/lib/mysql/mysql.sock
 [2002-04-25 17:23 UTC] edink@php.net
4.2.0 was packed with configure script made by autoconf 2.52 which doesn't seem to work correcly.
configure built with autoconf 2.13 works fine.

Resolutions:
* wait for 4.2.1 (due in a week or so)
* if you have autoconf 2.13 on you system, delete configure and run
./buildconf
* download configure script from http://www.edin.dk/php/configure.gz

 [2002-05-01 09:52 UTC] jason at revengefactory dot com
My load is doing the same thing on Mandrake 8.2.  Any ideas of what I can check to make sure this isn't a user error?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 06:01:30 2024 UTC