Last modified: 2014-06-01 13:30:03 UTC
The new mysqli adapter in 1.22.0 does not properly implement non-standard MySQL ports. While mysql_connect accepts an optional port number in the host parameter, mysqli's real_connect does not. Instead, using an explicit parameter is expected: bool mysqli::real_connect ([ string $host [, string $username [, string $passwd [, string $dbname [, int $port [, string $socket [, int $flags ]]]]]]] ) ^^^^^^^^^^ The current implementation just sets 'null' and provides the 'ip:port' string as $host parameter, resulting in failures such as "DB connection error: Unknown MySQL server host '127.0.0.1:4306'". I could provide a patch if needed, I'm not sure though if this should use $wgDBport (which would fix bug 36300 at the same time), or if the performance hit from exploding the port every time is acceptable.
Sounds like fallout from bug 45288. CC'ing Chad.
I have php 5.4.22 on my server, compiled with '--with-mysql' '--with-mysqli=...' '--with-pdo-mysql=...' I get the following errors: DB connection error Server: myserver:1234 , User: <user>, Password: <password>, error: :real_connect(): (HY000/2005): Unknown MySQL server host 'myserver:port' (2) Failed to connect to database 0 at myserver:1234 when I enter $wgDBServer = 'myserver:1234'; DB connection error Server: myserver, User: <user>, Password: <password>, error: :real_connect(): (28000/1045): Access denied for user '<user>'@'myserver' (using password: YES) Failed to connect to database 0 at myserver when I enter $wgDBServer = 'myserver'; $wgDBport = 1234;
Update per https://www.mediawiki.org/w/index.php?title=MediaWiki_1.22/Known_issues&oldid=847749 which seems to be the master list.
It is a bit confusing that $wgDBport is only used for postgres. So a patch that uses $wgDBport would be great.
Meanwhile adding the following in LocalSettings.php can be a possible workaround on some systems, I've seen it work on one system and fail on another: ini_set('mysqli.default_port', 3333);
*** Bug 59657 has been marked as a duplicate of this bug. ***
Change 109634 had a related patch set uploaded by Mglaser: Make MySQLi work with non-standard port (bug 58153) https://gerrit.wikimedia.org/r/109634
It turns out that this fix is not as simple as thought. $wgDBport is set to 5432. If I make mysqli consider $wgDBport by default, all instances using mysqli on 3306 will be broken. Further, running PHP 5.6 it seems to be ok to use hostname:port. So my attempt to fix this for now is to parse the port off the hostname. This needs to work for IPv4 and IPv6 as well. See https://gerrit.wikimedia.org/r/#/c/109634/. Please review and comment.
(In reply to comment #8) > It turns out that this fix is not as simple as thought. $wgDBport is set to > 5432. If I make mysqli consider $wgDBport by default, all instances using > mysqli on 3306 will be broken. Can't this be refactored to default to null and be overwritten in the specific database implementations should the value not be set by the user? > Further, running PHP 5.6 it seems to be ok to > use hostname:port. > So my attempt to fix this for now is to parse the port off the hostname. This > needs to work for IPv4 and IPv6 as well. See > https://gerrit.wikimedia.org/r/#/c/109634/. Please review and comment. That won't handle the syntax for persistent connections correctly which is 'p:<host>:<port>'.
(In reply to comment #9) > That won't handle the syntax for persistent connections correctly which is > 'p:<host>:<port>'. 'p:<host>' of course for earlier versions. ;)
I experienced what looks like a manifestation of the same bug. Running php maintenance/update.php from the command line with what I knew were correct credentials, I had the response DB connection error: Unknown MySQL server host 'localhost:/tmp/mysql5.sock' (34) (localhost:/tmp/mysql5.sock) The answer in my case was to change the DB host from $wgDBserver = "localhost:/tmp/mysql5.sock" to just $wgDBserver = "localhost" My thanks to Ciencia Al Poder who pointed me here, and my ISP support who suggested the above.
(In reply to comment #11) > DB connection error: Unknown MySQL server host 'localhost:/tmp/mysql5.sock' > (34) (localhost:/tmp/mysql5.sock) How did you end up with "localhost:/tmp/mysql5.sock" in your LocalSettings.php? Did you modify that setting or is that what MediaWiki gave you?
It was what my ISP told me to use when I first set up Wikimedia a couple of years ago and couldn't get a connection. It worked then, and it worked up to the time I updated to 1.22.
Change 109634 had a related patch set uploaded by Mglaser: Make MySQLi work with non-standard port https://gerrit.wikimedia.org/r/109634
Change 109634 merged by jenkins-bot: Make MySQLi work with non-standard port https://gerrit.wikimedia.org/r/109634
Change 119735 had a related patch set uploaded by Mglaser: Make MySQLi work with non-standard port https://gerrit.wikimedia.org/r/119735
Change 119735 merged by jenkins-bot: Make MySQLi work with non-standard port https://gerrit.wikimedia.org/r/119735
now merged in master and backported to release 1.22.5
(In reply to Mark A. Hershberger from comment #12) > (In reply to comment #11) > > DB connection error: Unknown MySQL server host 'localhost:/tmp/mysql5.sock' > > (34) (localhost:/tmp/mysql5.sock) In 1.22.5 I have exactly the same socket problem > How did you end up with "localhost:/tmp/mysql5.sock" in your > LocalSettings.php? Did you modify that setting or is that what MediaWiki > gave you? https://www.mediawiki.org/wiki/Manual:Config_script This bug should be reopened.
Stefan: Is this also a setting your provider recommended (see comment 12)? Did you check that the code change in https://gerrit.wikimedia.org/r/#/c/119735/ is in place on the server, just to make sure?
(In reply to Andre Klapper from comment #20) > Stefan: Is this also a setting your provider recommended (see comment 12)? No, it was setting suggested on https://www.mediawiki.org/wiki/Manual:Config_script > Did you check that the code change in > https://gerrit.wikimedia.org/r/#/c/119735/ is in place on the server, just > to make sure? Yes, it is. With original settings: $wgDBserver = "localhost:/var/lib/mysql/mysql.sock"; it doesn't work and after change in LocalSettings.php: -#$wgDBserver = "localhost:/var/lib/mysql/mysql.sock"; +$wgDBport = "/var/lib/mysql/mysql.sock"; it works again.
(In reply to Stefan Plewako :stef from comment #21) > With original settings: > $wgDBserver = "localhost:/var/lib/mysql/mysql.sock"; > > it doesn't work and after change in LocalSettings.php: > -#$wgDBserver = "localhost:/var/lib/mysql/mysql.sock"; > +$wgDBport = "/var/lib/mysql/mysql.sock"; > > it works again. What if you don't add $wgDBport? Does it work then? I think it should since, IIRC, /var/lib/mysql/mysql.sock is the standard connection for localhost on Debian.
(In reply to Mark A. Hershberger from comment #22) > What if you don't add $wgDBport? Does it work then? Yes, it works without $wgDBport and $wgDBserver