Media Wiki Search Error

For more information on MediaWiki, visit


If you ever move an database driven application, you always can run the risk of something getting corrupted along the way. MediaWiki is no exception. Moving this wiki to a hosted solution yielded an error that resulted in the following message appearing any time that I tried to run a standard search for content in my wiki:

A database query syntax error has occurred. This may indicate a bug in the software.
The last attempted database query was: (SQL query hidden)
from within function "SearchMySQL::searchInternal".
Database returned error "144: Table './xxxwiki/searchindex' is marked as crashed
and last (automatic?) repair failed (localhost).

Database Fix:

As luck would have it, the fix for this is a fairly simple one. First you need to log into the database server hosting the database for the MediaWiki application. Select or "use" the database and remove the corrupted searchindex table, and create a fresh one to take it's place. This can be done by using the following sql statement:d

DROP TABLE `searchindex`;
CREATE TABLE `searchindex` (
  `si_page` INT(10) UNSIGNED NOT NULL,
  `si_title` VARCHAR(255) NOT NULL DEFAULT '',
  `si_text` mediumtext NOT NULL,
  UNIQUE KEY `si_page` (`si_page`),
  FULLTEXT KEY `si_title` (`si_title`),
  FULLTEXT KEY `si_text` (`si_text`)

Regen Search Index:

Once the fresh database table has been created, the search index will need to be refreshed. Again as luck would have it, those fine developers over at MediaWiki have included a script in the installation that does exactly that.

SSH over to your MediaWiki server and cd into the maintenance folder under the wiki install folder. For example on a linux host, it may be somewhere like:

cd /var/www/html/mysite/mediawiki-1.19.1/maintenance

Once in the directory, reindex the site using either the rebuildtextindex.php or the rebuildall.php script.

php rebuildtextindex.php

Hosted Instance Gotcha:

In the event that you are also are using a hosted solution, PHP may have the register_argc_argv variable set to off. In which case, the reindex will fail with an error message that says:

Content-type: text/html

Cannot get command line arguments, register_argc_argv is set to false

If that is the case, you can create a custom php.ini file, which sets the register_argc_argv="On" directive and run the script specifying that custom php.ini file. In my case, my hosting provider allows me to have a custom php.ini file in my account that I can modify. I don't however have the ability to restart apache, which is usually required when making changes to the php.ini file, but php does give you the ability to specify the custom php.ini file on execution, and will honor the values set in that file. So in order to run the index rebuild script, we now run the following command:

php -c ../../../php.ini rebuildtextindex.php
Content-type: text/html

Dropping index...
Rebuilding index fields for 697 pages...

Rebuild the index...

Once complete, you should have a functional search in your mediawiki again :)