LoginSignup
14
11

More than 5 years have passed since last update.

MySQLのSELECT結果をCSV形式で出力する

Posted at

SELECT結果を直接CSV出力する方法。
今回は、sqlファイルを作成しコマンドラインから直接出力する。

SQLファイル
query.sql
SELECT * FROM tables
INTO OUTFILE '/tmp/output.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"';
コマンドラインで実行
% cat query.sql | mysql -u root -p [database]
14
11
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
14
11