0
0

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

csvファイルをmysql5.7にimportする方法

Posted at

csvファイルをmysql5.7にimportする方法

背景

データがcsvで共有されているため、それを手元のmysql5.7に入れたい。

/var/lib/mysql-files/に移動

移動しないと以下のエラーが出る

The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

importする

linuxサーバではdefaultではセキュリティーの問題でLOAD DATA LOCALコマンドが使えなくなっている。
以下のようなエラーが出る。

The used command is not allowed with this MySQL version

mysql接続時に--local-infile=1オプションを渡す。

mysql -uuser -ppassword -hhost --local-infile=1

load dataコマンド使い方

LOAD DATA LOCAL INFILE '/var/lib/mysql-files/hoge.csv' INTO TABLE table FIELDS TERMINATED BY ',' ENCLOSED BY '"' IGNORE 1 LINES;

TERMINATED BY 区切り文字

ENCLOSED BY フィールドを囲むキャラクタ

IGNORE 1 LINES 何行importしないか

詳しいオプション

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?