FS#17179 - [php] Change default mysql socket path

Attached to Project: Arch Linux
Opened by Evangelos Foutras (foutrelis) - Tuesday, 17 November 2009, 22:17 GMT
Last edited by Pierre Schmitz (Pierre) - Monday, 23 November 2009, 23:12 GMT
Task Type Bug Report
Category Packages: Extra
Status Closed
Assigned To Pierre Schmitz (Pierre)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 5
Private No

Details

Description:

The new MySQL package (5.1.40-1) has moved mysql.sock to /tmp/mysqld/mysql.sock. Therefore, the socket path passed to PHP during compilation needs to be adjusted.

Additional info:
* php 5.3.0-5
* mysql 5.1.40-1

Bug report requesting the path change: http://bugs.archlinux.org/task/14488 ([mysql] use standard directories for mysql config and mysqld.pid files )
This task depends upon

Closed by  Pierre Schmitz (Pierre)
Monday, 23 November 2009, 23:12 GMT
Reason for closing:  Fixed
Additional comments about closing:  added workaround/patch until fixed by upstream
Comment by Radu Potop (wooptoo) - Tuesday, 17 November 2009, 22:41 GMT
I can confirm this. Current socket path breaks PHP.
Comment by Jan de Groot (JGC) - Tuesday, 17 November 2009, 22:49 GMT
Why was this moved to /tmp/mysql/ in the first place? The correct location for socket- and pid files is /var/run/, maybe even /var/run/mysql/, but not /tmp/mysql.
Comment by Andrea Scarpino (BaSh) - Wednesday, 18 November 2009, 02:56 GMT
@Jan
yes this make no sense, sock file will be into /var/run/mysqld/ with mysql-5.1.40-2
Comment by Alexandre Courbot (Gnurou) - Thursday, 19 November 2009, 01:47 GMT
Indeed, after upgrading my Drupal instance became completely unusable until I created a link from /tmp/mysql.sock to /tmp/mysqld/mysql.sock. Would be nice if PHP was updated to reflect the future change to /var/run.
Comment by Andrea Scarpino (BaSh) - Thursday, 19 November 2009, 01:51 GMT
yes, I lost the whole day trying to fix this. I am building mysql 5.1.41-2 that should fix everything.
Comment by Alexandre Courbot (Gnurou) - Thursday, 19 November 2009, 01:56 GMT
Thanks - will check it out as soon as its available.
Comment by Evangelos Foutras (foutrelis) - Thursday, 19 November 2009, 10:20 GMT
PHP should probably be rebuilt against mysql 5.1.41-2 because the pdo_mysql extension takes the socket path from `mysql_config --socket' which in versions <5.1.41-2 still points at /tmp/mysql.sock (and --with-mysql-sock=/var/run/mysqld/mysqld.sock, of course).
Comment by Andrea Scarpino (BaSh) - Thursday, 19 November 2009, 11:38 GMT
I already tried that and php still doesn't work
Comment by Evangelos Foutras (foutrelis) - Thursday, 19 November 2009, 11:45 GMT
I rebuild my php52 aur package with '--with-mysql-sock=/var/run/mysqld/mysqld.sock' for a server I'm managing and it worked fine.

I'll try with PHP 5.3 since you mention that it has problems.
Comment by Evangelos Foutras (foutrelis) - Thursday, 19 November 2009, 12:28 GMT
Confirmed. It appears that mysqlnd (the native driver PHP 5.3 has for mysql) looks specifically for /tmp/mysql.sock (see ext/mysqlnd/mysqlnd.c, around line 539).

PHP 5.3.1 doesn't seem to do anything differently regarding the above, so it may need to be patched.
Comment by Evangelos Foutras (foutrelis) - Thursday, 19 November 2009, 12:34 GMT
Actually, scratch that. The mysqlnd_connect function uses '/tmp/mysql.sock' only if another socket path hasn't been specified when it's called.
Comment by Pierre Schmitz (Pierre) - Thursday, 19 November 2009, 13:07 GMT
Right, looks like I have to patch mysqlnd. Calling mysql without specifying the socket worked before. So requiring this now would be a nasty regression.
Comment by Evangelos Foutras (foutrelis) - Thursday, 19 November 2009, 13:07 GMT
Looking at ext/mysql/config.m4, it seems to me that the socket path we specify is not taken into account when we build with mysqlnd.

I'm testing a patch right now to verify this assumption.
Comment by Pierre Schmitz (Pierre) - Thursday, 19 November 2009, 13:18 GMT
Yes, I think this is correct. The sock configure parameter is not used within mysqlnd.
Comment by Evangelos Foutras (foutrelis) - Thursday, 19 November 2009, 13:55 GMT
I think it's supposed to be used by the mysql/mysqli/pdo_mysql extensions which call mysqlnd_connect with a socket parameter. However, PHP_MYSQL_UNIX_SOCK_ADDR doesn't seem to get defined when mysqlnd is enabled.

I'm attaching the patch I'm trying to test, but I'm having trouble recreating the configure script (autoreconf freaks out O.o).
Comment by Pierre Schmitz (Pierre) - Thursday, 19 November 2009, 14:12 GMT
Nice try. ;) I think this one should be reported upstream.

I tried to build it with mysqlnd.c patched. Of course I can connect now, but utf8 does not work anymore. This is unrelated to this bug but will delay the release of a new php package. For now I'd recommend to downgrade the mysql packages. Those should never have been moved to extra in their current state.
Comment by Evangelos Foutras (foutrelis) - Thursday, 19 November 2009, 15:01 GMT
Reported upstream: http://bugs.php.net/bug.php?id=50231. In the mean time, Pierre's patch solves this issue. :)
Comment by Evangelos Foutras (foutrelis) - Thursday, 19 November 2009, 15:11 GMT
Pierre, how do you mean utf8 doesn't work? I upgraded a server to mysql-5.1.41-2 today, along with php52-5.2.11-3 from the AUR [1]. A Drupal site that's hosted on this server still functions correctly. Maybe it's a problem with PHP 5.3.1 or mysqlnd? .-.

----
[1] http://aur.archlinux.org/packages.php?ID=30384
Comment by Pierre Schmitz (Pierre) - Thursday, 19 November 2009, 15:16 GMT
I am on it. For now it seems that utf8 is working in general. I just have problems with an old database. But that one might just be broken.
Comment by Jan de Groot (JGC) - Thursday, 19 November 2009, 15:22 GMT
If the default collation is UTF8, you have to call "SET NAMES latin1" or whatever is your charset/collation to work with non-UTF8 input. Without that option, anything that is non-UTF8 will get corrupted or even chopped.
Comment by Pierre Schmitz (Pierre) - Thursday, 19 November 2009, 16:08 GMT
If I dump my db using "--default-character-set=latin1 -c --insert-ignore --skip-set-charset" and then import into the new DB utf8 works as expected. I am still not sure what went wrong here. Maybe I missed some character conversion during the 4.0->4.1 upgrade. But that's going a little off-topic.

@Evangelos Foutras (foutrelis): Thanks for filing an upstream report.
Comment by Pierre Schmitz (Pierre) - Thursday, 19 November 2009, 16:51 GMT
So, php-*-5.3.1-1-x86_64 uses the new socket now.
Comment by Evangelos Foutras (foutrelis) - Thursday, 19 November 2009, 17:56 GMT
Nice work Pierre. It connects fine now, without any socket path specification in /etc/php/php.ini.
Comment by Andrea Scarpino (BaSh) - Thursday, 19 November 2009, 19:50 GMT
yeah!! good job Pierre!
Comment by Evangelos Foutras (foutrelis) - Thursday, 19 November 2009, 21:19 GMT
  • Field changed: Percent Complete (100% → 0%)
The pdo_mysql extension still looks for /tmp/mysql.sock. Was php-5.3.1-1 built against mysql-5.1.41-2 or -1?
Comment by Evangelos Foutras (foutrelis) - Thursday, 19 November 2009, 21:29 GMT
Sorry, I should have checked earlier, before saying that it works fine.

[foutrelis@failboat ~]$ strings /usr/lib/php/modules/pdo_mysql.so | grep sock
pdo_mysql.default_socket
/tmp/mysql.sock
unix_socket

Also see my previous comment: http://bugs.archlinux.org/task/17179#comment53409
Comment by Pierre Schmitz (Pierre) - Thursday, 19 November 2009, 21:58 GMT
Looks like pdo is sufferd by the smae bug as mentioned above. PDO_MYSQL_UNIX_ADDR is not set during configure. Until this is fixed upstream I'll simply patch the hardcoded path here as well.
Comment by Evangelos Foutras (foutrelis) - Thursday, 19 November 2009, 22:10 GMT
Yes, you're right; it's the same situation. >.<

I'll include this information in the bug report upstream.
Comment by Pierre Schmitz (Pierre) - Thursday, 19 November 2009, 23:17 GMT
OK, pdo should be fixed in -2.
Comment by Evangelos Foutras (foutrelis) - Friday, 20 November 2009, 10:18 GMT
I think there is still an issue. When pdo_mysql.default_socket is empty (the default), it will fail with:

[foutrelis@foutboxd ~]$ php -r 'new PDO("mysql:", "root");'
PHP Warning: PDO::__construct(): [2002] Invalid argument (trying to connect via unix://) in Command line code on line 1
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] Invalid argument' in Command line code:1
Stack trace:
#0 Command line code(1): PDO->__construct('mysql:', 'root')
#1 {main}
thrown in Command line code on line 1

But when it's commented out, or set to /var/run/mysqld/mysqld.sock, it will work as expected:

[foutrelis@foutboxd ~]$ php -r 'new PDO("mysql:", "root");'
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: NO)' in Command line code:1
Stack trace:
#0 Command line code(1): PDO->__construct('mysql:', 'root')
#1 {main}
thrown in Command line code on line 1

Hums. .-.
Comment by Evangelos Foutras (foutrelis) - Friday, 20 November 2009, 12:26 GMT
Took me a while, but I tracked this bug down!

The attached patch makes pdo_mysql use the pdo_mysql.default_socket in php.ini only if it's nonempty.

Can be applied with:

# don't use empty pdo_mysql.default_socket from php.ini
patch -p1 -i ${srcdir}/pdo-mysql-default-socket-nonempty.patch || return 1

I'll file a bug report upstream to get this fixed in future versions.
Comment by Evangelos Foutras (foutrelis) - Friday, 20 November 2009, 12:29 GMT Comment by Evangelos Foutras (foutrelis) - Monday, 23 November 2009, 15:57 GMT
Patch regarding pdo_mysql.default_socket has been merged upstream. The bug itself is not critical so I guess it can wait until PHP 5.3.2 is released. :)
Comment by Pierre Schmitz (Pierre) - Monday, 23 November 2009, 21:42 GMT
I have added the patch to -3. Well, even though PDO isn't used by that many projects it's a regression that breaks code that had worked before.
Comment by Evangelos Foutras (foutrelis) - Monday, 23 November 2009, 21:53 GMT
Thanks Pierre.

Loading...