シェルでMySQLを実行し、csvファイルに書き出す
descでカラム一覧を表示して、その結果をcsvファイルに出力したかった。
けどそのファイル出力を50回しないといけなくてとても面倒なのでシェルでかいてみた。
columns_list.txtにはカラム名が書かれているテキストファイル。
以下シェルプログラム
#!/bin/bash while read columns do sql="desc $columns" mysql -uroot -proot -e "$sql" db_name > ~/columns_csv/$columns.csv done < columns_list.txt
書き出せたけどWarningがでる。
[Warning] Using a password on the command line interface can be insecure.
/Applications/MAMP/conf/my.cnfで以下のプログラムを追加したけど、Warningは消えなかったなぁ🤔
[client] user = root password = root host = localhost
参考
【シェルスクリプト】ファイルの中身を一行ずつ読み込む方法 | server-memo.net
MySQL5.6のUsing a password on the command line interface can be insecureの対応 - 文系プログラマによるTIPSブログ