LoginSignup
5
3

More than 5 years have passed since last update.

shellでSQLの出力をCSVに変換する方法

Last updated at Posted at 2016-02-03

便利だったのでメモします。

説明

mysqlのコマンドを打つと下記のような出力になります。

コマンド
mysql -u root --execute="select user, host from mysql.user where host=\"127.0.0.1\";"
出力
+------+-----------+
| user | host      |
+------+-----------+
| root | 127.0.0.1 |
+------+-----------+

trというコマンドを下記のように使うと、csv形式に変換できます。

コマンド
mysql -u root --execute="select user, host from mysql.user where host=\"127.0.0.1\";" | tr '\t', ','
出力
user,host
root,127.0.0.1

もっと良い方法があれば、情報を共有して頂けると嬉しいです。

参考

5
3
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
5
3