Difference between revisions of "Migrating mediawiki from mysql to sqlite"

From Linuxintro
imported>ThorstenStaerk
imported>ThorstenStaerk
(works as designed: https://www.mediawiki.org/wiki/Manual:User_table#user_options)
Line 32: Line 32:
 
  chown wwwrun:www /srv/www/htdocs/wikidb.sqlite
 
  chown wwwrun:www /srv/www/htdocs/wikidb.sqlite
  
I will admit that I still have some more things to explore here - my "user" table does not contain a field "user_options". But maintenance/sqlite/archives/initial-indexes.sql is called by update.php and requires this.
+
I will admit that I still have some more things to explore here.
 +
 
 +
== Error ==
 +
When editing an article ''article'' I get the error message
 +
The revision #0 of the page named "''article''" does not exist.
 +
 
 +
$old_id = $dbw->nextSequenceValue( 'text_old_id_seq' );
 +
 
 
I guess it fails in line 1291 of includes/Revision.php
 
I guess it fails in line 1291 of includes/Revision.php
 
I am getting The revision #0 of the page named "Tutorials/C Programming Tutorial" does not exist.
 
  
 
problem is
 
problem is

Revision as of 15:02, 10 September 2013

Overview

To migrate a mediawiki from MySQL to SQLite there are two basic approaches:

  • start with a new database and worry about
    • dumping all pages but the Main Page with the dumpBackup command and restoring them with the importDump command
    • keeping the articles' revisions
    • copying the Main Page from the old wiki to the new
    • copying the users and privileges from the old wiki to the new
    • copying the wiki statistics (like page visits) from the old wiki to the new
    • copying images and other files from the old wiki to the new
    • re-doing things like mediawiki extensions on the new wiki
    • re-doing your settings e.g. from LocalSettings.php on the new wiki
Matt gives a good overview about this
  • just migrate the database below your wiki

migrate database below your wiki

I wanted to migrate the database below my wiki so

  • I created a dump (aka backup aka export) of the database
mysqldump wikidb -u wikiuser -p > dump.sql
  • I got a MySQL -> SQLite converter
wget https://gist.github.com/esperlu/943776/raw/dd87f4088f6d5ec7563478f7a28a37ba02cf26e2/mysql2sqlite.sh
  • I started this converter to create a file /srv/www/htdocs/wikidb.sqlite:
sh mysql2sqlite.sh -u wikiuser -p wikidb | sqlite3 /srv/www/htdocs/wikidb.sqlite
  • change LocalSettings.php to reflect
$wgDBtype = "sqlite";
$wgDBserver = "";
$wgDBname = "wikidb";
$wgDBuser = "";
$wgDBpassword = "";
$wgSQLiteDataDir = "/srv/www/htdocs";
  • allow your webserver to write to the file:
chown wwwrun:www /srv/www/htdocs/wikidb.sqlite

I will admit that I still have some more things to explore here.

Error

When editing an article article I get the error message

The revision #0 of the page named "article" does not exist.

$old_id = $dbw->nextSequenceValue( 'text_old_id_seq' );

I guess it fails in line 1291 of includes/Revision.php

problem is

SELECT  mr_blob,mr_resource,mr_timestamp  FROM phase3msg_resource  WHERE mr_resource IN ('user.options','user.tokens')  AND mr_lang = 'en'

more general:

sqlite> select * from phase3msg_resource;
Error: database disk image is malformed

TroubleShooting

I got quite a lot of error messages that were easy to fix - provided you know how.

PDO exception

Symptom: When surfing to the wiki you get a page displaying this error message:

Unexpected non-MediaWiki exception encountered, of type "PDOException"
exception 'PDOException' with message 'There is no active transaction' in /srv/www/htdocs/mediawiki/includes/db/DatabaseSqlite.php:664
Stack trace:

Solution: In LocalSettings.php set all occurrences of $wgDBuser to "".

$wgDBuser = "";

Is not unique

Symptom: When calling mysql2sqlite.sh you get a lot of error messages like

Error: near line 565: column cat_id is not unique
Error: near line 566: column cat_id is not unique

Solution: You cannot call mysql2sqlite.sh twice to the same target file. Delete the target file before you start the next conversion, like this:

rm test.sqlite
sh /root/mysql2sqlite.sh -u wikiuser -p wikidb | sqlite3 test.sqlite

file is encrypted or not a database

Symptom: When trying to open the sqlite database on the command line you get the error message

Unable to open database "../../data/my_wiki.sqlite": file is encrypted or is not a database

Solution: In my case I used the command sqlite to open the database. sqlite pointed to version 2 of sqlite. When I replaced the command sqlite by sqlite3 it worked:

tweedleburg:/srv/www/htdocs/mediawiki # sqlite ../../data/my_wiki.sqlite 
Unable to open database "../../data/my_wiki.sqlite": file is encrypted or is not a database
tweedleburg:/srv/www/htdocs/mediawiki # sqlite3 ../../data/my_wiki.sqlite 
SQLite version 3.7.12.1 2012-05-22 02:45:53
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>

See also