0
1

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 3 years have passed since last update.

mysqlにcsvを読み込み

Last updated at Posted at 2020-03-16
  • 環境

 mysql Ver 14.14
 ubuntu16.04

csvを用意しておく

# mysqlにログイン
$ sudo mysql -u root -p

# database作成
mysql> create database database_name

# databaseを選択
mysql> use database_name

# テーブルを作成し、カラム情報も同時に設定
mysql> create table table_name(
    -> id int,
    -> name varchar(255),
    -> ...
    -> ); 

mysql> load data local infile "file_path/file.csv " into table table_name fields terminated by ',' optionally enclosed by '"';

下記のようなログが出ていれば多分OK

Query OK, XXX rows affected, YYY warnings (ZZZ sec)
Records: XXX Deleted: 0 Skipped: 0 Warnings: YYY

# テーブルを確認
mysql> show tables;

# テーブルの中身まで確認したい場合
mysql> desc table_name;

参考:
http://shiningcureseven.hatenablog.com/entry/2018/08/03/122221

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?