Last modified: 2014-06-01 13:30:03 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T60153, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 58153 - mysqli: Non-standard port handling broken (explicit parameter int $port expected)
mysqli: Non-standard port handling broken (explicit parameter int $port expec...
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
Database (Other open bugs)
1.22.0
All All
: High major with 1 vote (vote)
: 1.22.x release
Assigned To: Nobody - You can work on this!
: code-update-regression
: 59657 (view as bug list)
Depends on: 45288
Blocks:
  Show dependency treegraph
 
Reported: 2013-12-07 13:57 UTC by Alex Legler
Modified: 2014-06-01 13:30 UTC (History)
11 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---
umherirrender_de.wp: Backport_to_Stable+


Attachments

Description Alex Legler 2013-12-07 13:57:50 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.
Comment 1 Andre Klapper 2013-12-09 13:21:22 UTC
Sounds like fallout from bug 45288. CC'ing Chad.
Comment 2 Dimitar Dimitrov 2013-12-10 13:28:50 UTC
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;
Comment 3 Nemo 2013-12-30 09:29:26 UTC
Update per https://www.mediawiki.org/w/index.php?title=MediaWiki_1.22/Known_issues&oldid=847749 which seems to be the master list.
Comment 4 Kasper Souren 2013-12-31 02:02:25 UTC
It is a bit confusing that $wgDBport is only used for postgres.
So a patch that uses $wgDBport would be great.
Comment 5 Kasper Souren 2014-01-02 14:50:19 UTC
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);
Comment 6 Kevin Israel (PleaseStand) 2014-01-05 01:09:48 UTC
*** Bug 59657 has been marked as a duplicate of this bug. ***
Comment 7 Gerrit Notification Bot 2014-01-27 09:19:33 UTC
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
Comment 8 Markus Glaser 2014-01-27 09:23:53 UTC
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.
Comment 9 Alex Legler 2014-01-27 10:02:25 UTC
(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>'.
Comment 10 Alex Legler 2014-01-27 10:04:36 UTC
(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. ;)
Comment 11 Roy Grubb 2014-02-06 13:40:25 UTC
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.
Comment 12 Mark A. Hershberger 2014-02-06 15:28:14 UTC
(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?
Comment 13 Roy Grubb 2014-02-07 05:43:49 UTC
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.
Comment 14 Gerrit Notification Bot 2014-02-24 21:24:23 UTC
Change 109634 had a related patch set uploaded by Mglaser:
Make MySQLi work with non-standard port

https://gerrit.wikimedia.org/r/109634
Comment 15 Gerrit Notification Bot 2014-03-14 22:43:28 UTC
Change 109634 merged by jenkins-bot:
Make MySQLi work with non-standard port

https://gerrit.wikimedia.org/r/109634
Comment 16 Gerrit Notification Bot 2014-03-20 11:07:27 UTC
Change 119735 had a related patch set uploaded by Mglaser:
Make MySQLi work with non-standard port

https://gerrit.wikimedia.org/r/119735
Comment 17 Gerrit Notification Bot 2014-03-25 15:54:33 UTC
Change 119735 merged by jenkins-bot:
Make MySQLi work with non-standard port

https://gerrit.wikimedia.org/r/119735
Comment 18 Umherirrender 2014-03-26 17:27:59 UTC
now merged in master and backported to release 1.22.5
Comment 19 Stefan Plewako :stef 2014-04-01 18:35:41 UTC
(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.
Comment 20 Andre Klapper 2014-04-04 11:55:22 UTC
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?
Comment 21 Stefan Plewako :stef 2014-04-09 09:30:48 UTC
(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.
Comment 22 Mark A. Hershberger 2014-04-09 14:50:10 UTC
(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.
Comment 23 Stefan Plewako :stef 2014-04-10 11:22:32 UTC
(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

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links