EmbulkのMySQLからの読み込みのメモ。
|
|
MySQLのテーブルから読み込むにはembulk-input-mysqlを使う。
このプラグインを使う為には、embulk-input-mysqlプラグインをインストールしておく必要がある。
$ embulk gem install embulk-input-mysql $ embulk gem list embulk-input-mysql 2015-09-27 01:54:03.379 +0900: Embulk v0.7.4 *** LOCAL GEMS *** embulk-input-mysql (0.6.0)
in: type: mysql host: 192.168.1.1 user: hishidama password: "password" database: hishidamadb table: embulk_example select: "id, account, time, purchase, comment" where: "comment <> 'embulk'" out: 〜
直接SQL(SELECT文)を書きたい場合は、table/select/whereではなくqueryを使う。
in: type: mysql host: 192.168.1.1 user: hishidama password: "password" database: hishidamadb query: | select id, account, time, purchase, comment from embulk_example where comment <> 'embulk' out: 〜
オプション名 | 説明 | ymlの記述例 | デフォルト値 |
---|---|---|---|
type |
type: mysql |
(必須) | |
host |
DBのホスト名。 |
host: 192.168.1.1 |
(必須) |
port |
DBのポート番号。 |
port: 3306 |
3306 |
user |
DBにログインするユーザー名。 |
user: hishidama |
(必須) |
password |
DBにログインする為のパスワード。 |
password: zzz |
空文字列(パスワード無し) |
database |
DB名。 |
database: hishidamadb |
(必須) |
query |
SELECT文。 |
query: | select column1, columne2 from example where column1 = 123 |
query または table(+select+where) のどちらかは必須。 |
table |
テーブル名。 |
table: example |
|
select |
カラム名。 |
select: "column1, column2" |
* |
where |
条件。 |
where: "column1 = 123" |
(全レコードが対象となる) |
fetch_rows |
一度にフェッチするレコード数。 | ||
options |
JDBC接続情報のオプション。 | ||
default_timezone |
デフォルトのタイムゾーン。 |
default_timezone: 'Asia/Tokyo' |
|
column_options |
カラムの出力定義。 MySQLのdateやtimestampをEmbulkでstringとして扱う際の形式を指定する。 |
column_options: col2: { type: string, timestamp_format: '%Y-%m-%d %H:%M:%S' } |
Embulk0.7.7から、別の設定ファイルを読み込めるようになった。[2015-10-31]
これにより、ホスト名やユーザー名・パスワード・DB名等を共通の設定ファイルに分離させることが出来る。
type: mysql host: 192.168.1.1 user: hishidama password: "password" database: hishidamadb
in: {% include 'common/mysql' %} table: embulk_example select: "id, account, time, purchase, comment" where: "comment <> 'embulk'" out: 〜
includeで読み込む設定ファイルのファイル名はアンダースコア「_」で始まっている必要があるが、includeで指定する際にはアンダースコアは付けない。