LoginSignup
2
2

More than 5 years have passed since last update.

MySQL, load data infile に流しこむtsvの形式メモ

Last updated at Posted at 2015-09-17

データ入れるまでに思ったよりも試行錯誤したので

基本的な

  • デフォルトはtsvファイル(タブ区切り)
  • 基本的にクオート不要
  • datetimeもクオート不要
  • NOW()とか関数指定してると当然怒られる
  • レコードの末尾のカラムまでtsvのカラムの個数が合わないとだめ
    • 末尾のcreated的なカラムなど、CURRENT_TIMESTAMPをデフォルト値にしてたりでも必要

1   testdata:1  2015-08-10 00:00:00 631     42
2   testdata:2  2015-08-11 00:00:00 781     60
3   testdata:3  2015-08-12 00:00:00 851     35
4   testdata:4  2015-08-13 00:00:00 1308    32
5   testdata:5  2015-08-14 00:00:00 1391    44

コマンド例

$ mysql
mysql > load data infile "/file/to/path/testdata.csv" INTO TABLE test_table_name;
2
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
2
2