MySQL select to file

兩種儲存MySQL資料到檔案的方法

Piping the SQL into the database

echo "SELECT * FROM TABLE_NAME" | mysql -uUSERNAME -pPASSWORD DATABASENAME > /tmp/outfile.txt; 
 

Using an external SQL file.

mysql -uUSERNAME -pPASSWORD DATABASENAME < /tmp/sql.sql > /tmp/outfile.txt;