LoginSignup
4
2

More than 5 years have passed since last update.

mysqldump で出力した tsvを Redshift に import

Last updated at Posted at 2017-10-12

mysqldump で出力したTSVには下記のような特徴があって扱いがめんどくさいですが、Redshiftのオプション指定することで 無加工で Redshift に取り込めます。

  • nullは \N になる
  • フィールド内のタブ(\t) は、 \\t になる (\でエスケープされる)
  • フィールド内の改行(\n) は、 \\n になる (\でエスケープされる)

mysqldump で tsv として dumpする

mysql> select * from users into outfile '/var/lib/mysql-files/users.txt';

s3 に上げる

$ aws s3 cp /var/lib/mysql-files/users.txt s3://bucket_name/

Redshift にロード

$ psql -U $user $db_name --host=$host --port=5439

# copy table_name from 's3://bucket_name/users.txt'
iam_role 'arn:aws:iam::000000:role/HogeRole'
blanksasnull
emptyasnull
delimiter '\t'
escape
;

オプション

  • delimiter は タブ文字 \t を指定する
  • escape オプションつけることで、エスケープされた改行とタブをそのまま取り込める
  • csv オプションは指定しない
  • emptyasnull blanksasnull はなくても大丈夫と思う
4
2
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
4
2