以下のようにmysqlコマンドをパイプやリダイレクトで連携させたら、mysqlコマンドのメモリ使用量が急増しました。
動きを見ているとバッファリングされてしまっているみたい。全部結果を溜め込んでから、後ろに流すような動きです。
mysql $option -e "select col1,col2 from bigtable;" | command
mysql $option -e "select col1,col2 from bigtable;" > /path/to/outputfile
なんか良い方法無いかと調べたら、manに正にこの事象が書いてありました。 --quick
オプションで解決するということです。
当たり前のように書かれてるので、知らなかったのは自分だけなのかも・・
If you have problems due to insufficient memory for large result sets, use the --quick option. This forces mysql to retrieve results from the server a row at a time rather than retrieving the entire result set and buffering it in memory before displaying it.
以下のように --quick
オプション使うと解決です。
mysql $option --quick -e "select col1,col2 from bigtable;" | command