LoginSignup
0

More than 3 years have passed since last update.

MySQLでcsvファイルをテーブルにインポートする

Posted at

ログイン時、オプションを指定

mysql -u root -p --local-infile=1

データベースを選択

use hogedb

インポートするコマンド

LOAD DATA LOCAL INFILE './huga.csv' --インポートしたいcsvファイル
INTO TABLE hogetable --インポートするテーブル
FIELDS TERMINATED BY '\t' --インポートしたいcsvの区切り文字
LINES TERMINATED BY '\n'; --csvの行区切り指定

おまけ

インポート前に、格納済みのデータをクリアしたいときは

TRUNCATE TABLE hogetable;

別テーブルからデータを移行したいとき

insert into new_table (
 column1,
 column2,
 column3)
select
 column1,
 column2,
 column3,
from
 old_table;

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
0