FS#18563 - [php] 5.3.2 MySQL connection refused

Attached to Project: Arch Linux
Opened by Toni Viemerö (skithund) - Thursday, 04 March 2010, 20:22 GMT
Last edited by Pierre Schmitz (Pierre) - Thursday, 04 March 2010, 22:40 GMT
Task Type Bug Report
Category Packages: Extra
Status Closed
Assigned To Pierre Schmitz (Pierre)
Architecture x86_64
Severity Medium
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Once again PHP upgrade broke local MySQL connections.
Missing mysql-socket-patch?

Downgrading to 5.3.1-7 fixes things.
This task depends upon

Closed by  Pierre Schmitz (Pierre)
Thursday, 04 March 2010, 22:40 GMT
Reason for closing:  Not a bug
Comment by Pierre Schmitz (Pierre) - Thursday, 04 March 2010, 20:35 GMT
This was fixed upstream. It also seems to work fine here. I guess we need more information here about your my.cnf and php.ini. The default socket in my.cnf should be /var/run/mysqld/mysqld.sock while the socket in php.ini can be left unset.
Comment by Ionut Biru (wonder) - Thursday, 04 March 2010, 21:17 GMT
works for me too
Comment by Toni Viemerö (skithund) - Thursday, 04 March 2010, 21:54 GMT
my.cnf:
[mysqld]
socket = /var/run/mysqld/mysqld.sock

php.ini (via 'php -i'):
mysql.default_socket => /var/run/mysqld/mysqld.sock
mysqli.default_socket => /var/run/mysqld/mysqld.sock
pdo_mysql.default_socket => /var/run/mysqld/mysqld.sock

php values are empty in php.ini
Comment by Pierre Schmitz (Pierre) - Thursday, 04 March 2010, 21:56 GMT
Looks fine to me.
Comment by Toni Viemerö (skithund) - Thursday, 04 March 2010, 21:59 GMT
MySQL socket works fine from command line.

$ mysql --socket=/var/run/mysqld/mysqld.sock --protocol=socket -uXX -pXX test
Welcome to the MySQL monitor.
$ mysql -hlocalhost -uXX -pXX test
Welcome to the MySQL monitor.
Comment by Toni Viemerö (skithund) - Thursday, 04 March 2010, 22:13 GMT
This might actually be a PHP bug. Gotta go through PHP changelog and see what's changed.

...and a "misconfiguration" by me, since I'm connecting using "dbhost" instead of "localhost".
"dbhost" used to be another server, but due to hardware malfunction it's running locally temporarily.

For some odd reason it's using TCP instead of sockets. Problem solved by opening 3306 from iptables.

$ sudo pacman -U php-*5.3.2*xz
[...]
$ php -r "mysql_connect('dbhost', 'XX', 'XX');"
PHP Warning: mysql_connect(): [2002] Connection refused (trying to connect via tcp://dbhost:3306) in Command line code on line 1
$ sudo pacman -U php-*5.3.1-6*gz
[...]
$ php -r "mysql_connect('dbhost', 'XX', 'XX');"
$
Comment by Pierre Schmitz (Pierre) - Thursday, 04 March 2010, 22:18 GMT
If you define a hostname you tell mysql to use tcp. However, php will try to connect via socket if you set it to localhost. This unintuitive behavior might have confused you here. See http://de3.php.net/mysql_connect

and especially this note:

Note: Whenever you specify "localhost" or "localhost:port" as server, the MySQL client library will override this and try to connect to a local socket (named pipe on Windows). If you want to use TCP/IP, use "127.0.0.1" instead of "localhost". If the MySQL client library tries to connect to the wrong local socket, you should set the correct path as Runtime Configuration in your PHP configuration and leave the server field blank.
Comment by Toni Viemerö (skithund) - Thursday, 04 March 2010, 22:20 GMT
Maybe something to do with these:
http://bugs.archlinux.org/task/17179
http://bugs.php.net/50231

Thanks for listening :) This bug can now be closed as user error :)
Comment by Toni Viemerö (skithund) - Thursday, 04 March 2010, 22:22 GMT
Yeah, I understand TCP vs. socket difference, but I'm just confused why it was working before.
Comment by Pierre Schmitz (Pierre) - Thursday, 04 March 2010, 22:40 GMT
Might have been a side effect of the "self made" patch we had applied to 5.3.1.

Loading...