Page MenuHomePhabricator

MediaWiki 1.32.0 Installation Error: "Could not select database"
Closed, ResolvedPublic

Description

I get the following error when I try to install MediaWiki 1.32.0 on XAMPP:

/MediaWiki/mw-config/index.php?page=Upgrade Wikimedia\Rdbms\DBExpectedError from line 196 of C:\XAMPP\htdocs\MediaWiki\includes\libs\rdbms\database\DatabaseMysqli.php: Could not select database 'my_wiki'.

Backtrace:

#0 C:\xampp\htdocs\MediaWiki\includes\libs\rdbms\database\Database.php(2308): Wikimedia\Rdbms\DatabaseMysqli->doSelectDomain(Wikimedia\Rdbms\DatabaseDomain)
#1 C:\xampp\htdocs\MediaWiki\includes\libs\rdbms\database\Database.php(2301): Wikimedia\Rdbms\Database->selectDomain(Wikimedia\Rdbms\DatabaseDomain)
#2 C:\xampp\htdocs\MediaWiki\includes\installer\DatabaseInstaller.php(623): Wikimedia\Rdbms\Database->selectDB(string)
#3 C:\xampp\htdocs\MediaWiki\includes\installer\WebInstallerUpgrade.php(57): DatabaseInstaller->needsUpgrade()
#4 C:\xampp\htdocs\MediaWiki\includes\installer\WebInstaller.php(272): WebInstallerUpgrade->execute()
#5 C:\xampp\htdocs\MediaWiki\mw-config\index.php(79): WebInstaller->execute(array)
#6 C:\xampp\htdocs\MediaWiki\mw-config\index.php(38): wfInstallerMain()
#7 {main}

There's no database 'my_wiki' and no LocalSettings.php because it's a new installation. MediaWiki doesn't create the database on the 'Connect to database' page but reports the error. I hope this will be fixed because there was no error installing the earlier MediaWiki versions.

Event Timeline

I was going to say that probably the admin should create the database, but the documentations say clearly:

If you already have a database server and know the root password for it, the MediaWiki installation script can create a new database for you.

Even if one thinks that should not be true, the return should be a nice error message saying "please create a database", not an exception.

/mw-config/index.php?page=Upgrade should be accessed only when an existing MediaWiki database exists, but you said that "there's no LocalSettings.php because it's a new installation". Can you clarify what steps you did on the install wizard to get to that page?

Page 1
MediaWiki 1.32.0
LocalSettings.php not found.
Please set up the wiki first.

Page 2
Language
Continue

Page 3
Welcome to MediaWiki!
Continue

Page 4
Connect to database
Continue

MediaWiki Internal error
/MediaWiki/mw-config/index.php?page=Upgrade Wikimedia\Rdbms\DBExpectedError from line 196 of C:\XAMPP\htdocs\MediaWiki\includes\libs\rdbms\database\DatabaseMysqli.php: Could not select database 'my_wiki'.

Backtrace:

#0 C:\XAMPP\htdocs\MediaWiki\includes\libs\rdbms\database\Database.php(2308): Wikimedia\Rdbms\DatabaseMysqli->doSelectDomain(Wikimedia\Rdbms\DatabaseDomain)
#1 C:\XAMPP\htdocs\MediaWiki\includes\libs\rdbms\database\Database.php(2301): Wikimedia\Rdbms\Database->selectDomain(Wikimedia\Rdbms\DatabaseDomain)
#2 C:\XAMPP\htdocs\MediaWiki\includes\installer\DatabaseInstaller.php(623): Wikimedia\Rdbms\Database->selectDB(string)
#3 C:\XAMPP\htdocs\MediaWiki\includes\installer\WebInstallerUpgrade.php(57): DatabaseInstaller->needsUpgrade()
#4 C:\XAMPP\htdocs\MediaWiki\includes\installer\WebInstaller.php(272): WebInstallerUpgrade->execute()
#5 C:\XAMPP\htdocs\MediaWiki\mw-config\index.php(79): WebInstaller->execute(array)
#6 C:\XAMPP\htdocs\MediaWiki\mw-config\index.php(38): wfInstallerMain()
#7 {main}

There is no error installing MediaWiki 1.31.1.

Ok, I've tried a new 1.32 install and I'm able to reproduce the problem.

Same stack trace.

Looks like the installer first is trying to check if the target database exists by selecting that database (method Database->selectDB), the database doesn't exist, but instead of gracefully catching the error and continue with the creation of the database, it just fatals...

I'm very surprised this error didn't came up during the RC tests, since this is the first entry point of a new installation.

I think fe0af6cad578 caused this problem. In DatabaseMysqli::doSelectDomain(), if mysqli::select_db() return FALSE will manual throw the exception(DBExpectedError). This will definitely prevent a new installation.

We have these solutions:

  1. Remove the code that throws the exception. Make the code less strict. Or coding a new less strict method, and make the installer call it.
  2. Pass a parameter to DatabaseMysqli::doSelectDomain() to ignore the code that throws exception.
  3. Rewrite the logic of DatabaseInstaller, let the installer judge existence of the database by other ways.
RazeSoldier triaged this task as High priority.

Change 489665 had a related patch set uploaded (by 星耀晨曦; owner: 星耀晨曦):
[mediawiki/core@master] Use "try-catch" block instead of "if" block to prevent interruption of new installation

https://gerrit.wikimedia.org/r/489665

Change 489665 merged by jenkins-bot:
[mediawiki/core@master] Use "try-catch" block instead of "if" block to prevent interruption of new installation

https://gerrit.wikimedia.org/r/489665

Change 490687 had a related patch set uploaded (by 星耀晨曦; owner: 星耀晨曦):
[mediawiki/core@REL1_32] Use "try-catch" block instead of "if" block to prevent interruption of new installation

https://gerrit.wikimedia.org/r/490687

Change 490687 merged by jenkins-bot:
[mediawiki/core@REL1_32] Use "try-catch" block instead of "if" block to prevent interruption of new installation

https://gerrit.wikimedia.org/r/490687

This issue already fixed in REL1_32 and included in MW 1.32.1 (coming soon).

Aklapper renamed this task from MediaWiki 1.32.0 Installation Error to MediaWiki 1.32.0 Installation Error: "Could not select database".Feb 17 2019, 4:38 AM