Thursday, 23 August 2007

Specifying MySQL port on MediaWiki

MySQL listens on port 3306/tcp by default. MediaWiki's 1.7.1 configuration is a bit misleading when it comes to specifying the database port. This excerpt is from LocalSettings.php:
$wgdBserver = "localhost";
$wgDBname = "mw0";
$wgDBuser = "my_user";
$wgDBpassword = "my_pass";
$wgDBprefix = "mw_";
$wgDBtype = "mysql";
$wgDBport = "3308"; // <--- DOES NOT work for MySQL
The value in $wgBDport is only used with PostgreSQL. To specify a MySQL connection port different than 3306, use the syntax server:port on $wgdbServer. For instance:
$wgdBserver = "localhost:3308";
BUT! there's another catch: when the server is defined to "localhost", MySQL will default to connecting via socket. If you are changing the port in hopes of getting WikiMedia to connect to another running instance of MySQL, chances are that it will still connect to the "default" one. To force a TCP connection use the loopback IP address instead of "localhost":
$wgdBserver = "";
It took me nearly an hour to figure this bitch out so please say thank you if it works for you.

[Update 24/08/2007]: on Solaris my trick didn't work. To fix it, I had to add the following line to LocalSettings.php:
ini_set("mysql.default_socket", "/tmp/mysql5.sock");
Adjust the path to the location where your MySQL writes the socket and off you go!


Adrian A. Baumann said...


Caitlin said...

you rock -- I've been going around on this for a while.

Anonymous said...

+1 Thanks

Anonymous said...


Anonymous said...

Didn't work for me unfortunately