Wikimedia Developer Support

Cargo Database Query



I’m facing some issue while setting up cargo database and making an api query (attaching the screenshots for better clarification). I followed the installation manual for cargo which says to go to the maintenance directory and run php update.php to set up the two cargo database tables in the main database. But on executing update.php see the following debugging information :

MediaWiki 1.31.0-alpha Updater
Your composer.lock file is up to date with current dependencies!
[32a86f0d9f7e08e68807e0e9] [no req] Wikimedia\Rdbms\DBConnectionError from line 812 of /Applications/MAMP/htdocs/core/includes/libs/rdbms/database/Database.php: Cannot access the database: No such file or directory (localhost)
#0 /Applications/MAMP/htdocs/core/includes/libs/rdbms/loadbalancer/LoadBalancer.php(1093): Wikimedia\Rdbms\Database->reportConnectionError(string)
#1 /Applications/MAMP/htdocs/core/includes/libs/rdbms/loadbalancer/LoadBalancer.php(720): Wikimedia\Rdbms\LoadBalancer->reportConnectionError()
#2 /Applications/MAMP/htdocs/core/includes/GlobalFunctions.php(2887): Wikimedia\Rdbms\LoadBalancer->getConnection(integer, array, boolean)
#3 /Applications/MAMP/htdocs/core/maintenance/Maintenance.php(1296): wfGetDB(integer, array, boolean)
#4 /Applications/MAMP/htdocs/core/maintenance/update.php(144): Maintenance->getDB(integer)
#5 /Applications/MAMP/htdocs/core/maintenance/doMaintenance.php(94): UpdateMediaWiki->execute()
#6 /Applications/MAMP/htdocs/core/maintenance/update.php(245): require_once(string)
#7 {main}

Can someone help me with this?


Can you post your Cargo-related config? I guess you connect to the database via the socket but mediawiki did not find the socket file.


wfLoadExtension( ‘Cargo’ );
$wgShowExceptionDetails = true;
$wgShowDBErrorBacktrace = true;
$smwgEnabledCompatibilityMode = true;

I’m using the above lines to initialise cargo in my LocalSettings.php file.


Please comment wfLoadExtension( ‘Cargo’ );, then rerun update.php. Can the script be normal run?


No, it throws the same bunch of errors as above on commenting wfLoadExtension( ‘Cargo’ );


This means it is not caused by Cargo. Can you normally access your wiki? Are you set $wgDBserver = 'localhost'; in your LocalSettings.php?


Yes, you are right. Normally the wiki works fine. The home page and everything loads fine. But as soon as I try accessing the API (as shown in the above screenshot), it throws internal API error DBQueryError. All my DB configs are fine I suppose, DB server is set to localhost, DB name is fine, username password credentials are also fine as well. When I check my wiki database it does not contain any cargo tables that start with ‘cargo_’ as mentioned in the manual, so cargo is not completely setup which is another thing. I wonder where it is going wrong.


You can try set $wgDBserver = '';, then rerun update.php again.

#9 and feel similar.


Yep, tried that earlier, this also doesn’t work as well.


The port for mysql on my system is 3306. I have tried changing $wgDBserver = "localhost:3306"; but this doesn’t work as well. If I change it to $wgDBserver = ""; then the error string says ‘Connection Refused’. Tried changing my port to 8000 instead 8888 but this doesn’t help as well.


Try set $wgDBserver = '';. If the error persists, you need to check the connection to the database via the command line, mysql -h127.0.0.1 -u<username> -p.


Yep, the error persists. If I try connecting via the terminal, I can view the my_wiki database and access it via terminal, there is no issue in that. Did you mean anything else when you said check the connection?


Did you mean anything else when you said check the connection?

You can login mysql command line, but PHP shows Connection Refused. This may be caused by more complex reasons, I do not have a clue now. But I can recommend socket connections to you, this is faster than TCP/IP connection (except in Windows system). This way should set $wgDBserver = 'localhost:<socket file path>';. You can execute show variables like 'socket'; in mysql command line to find socket file path.


Did you create the page name called “Country” in your local build?


I’m really sorry, I got caught up with some other work and this thread totally slipped out of my mind. I was able to get past this issue. I’ll post the solution here for future reference of other community members.

The issue was with the execution of maintenance/update.php file to set up the database tables for cargo extension and for the record I was connecting to the database via a socket so this solution might make more sense if you are also doing the same. As mentioned in the installation guide of cargo if you place $wgShowSQLErrors = true; & $wgShowExceptionDetails = true; below wfLoadExtension( 'Cargo' ); in your ‘LocalSettings.php’ file then you can possibly get some helpful error messages, but in this case the error messages were not that informative.

With my issue @RazeSoldier was correct, there was a trouble with proper socket connection. I set up my $wgDBserver = 'localhost:<socket file path>'; and I was able to execute my update.php file. Socket file path can be found by executing show variables like 'socket'; in mysql command line.

As mentioned above by @aklapper these two links can also be helpful to anyone facing this issue:


Also refer this once.