6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

最新のWikiデータをMySQLにDumpする

Posted at

MySQLをインストール

※ インストール手順は省きます。

mysql> show variables like "chara%";

で全部utf-8なっていることを確認。

[mysqld]
...
character-set-server=utf8 #mysqldセクションの末尾に追加

[client]
default-character-set=utf8 #clientセクションを追加

ダメな場合は上記を/etc/my.cnfに追加。

xml2sqlをインストール

ダウンロードサーバがないので直接makeする。
https://github.com/Tietew/mediawiki-xml2sql

$ git clone https://github.com/Tietew/mediawiki-xml2sql.git
$ cd mediawiki-xml2sql
$ ./configure
$ make
$ sudo make install

wikiのdump用データをダウンロード

$ wget https://dumps.wikimedia.org/jawiki/latest/jawiki-latest-pages-articles.xml.bz2
$ bzip2 -d jawiki-latest-pages-articles.xml.bz2

データを以下のコマンドで変換

$ cat jawiki-latest-pages-articles.xml | sed -e 's/<dbname>.*<\/dbname>//' -e 's/<ns>.*<\/ns>//' -e 's/<parentid>.*<\/parentid>//' -e 's/<sha1>.*<\/sha1>//' -e 's/<model>.*<\/model>//' -e 's/<format>.*<\/format>//' -e 's/<redirect>.*<\/redirect>//' -e 's/<redirect.*\/>//' | xml2sql
mysql> select page.page_title from categorylinks left join page on categorylinks.cl_from = page.page_id where categorylinks.cl_to = '日本のタレント';
6
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?