Clevercode found a simple way to export MySQL data into CSV format.
1) MYSQL-E usage profile
Instructions for use: Execute an SQL statement and exit.
Format examples:
1) mysql-uroot-p123456-h 192.168.10.210-p 3306 db_logs-e "show databases;"
2) mysql-uroot-p123456-h 192.168.10.210-p 3306 db_logs-e "Select Cdate,uid,clientip,createtime from User_login_log Lim it 1; "
Description
-u:root is the user name;
-p:123456 for password
-h:mysql Server IP
-p:3306mysql Server Port
Db_logs: The database where the statement is executed
-E: The statement that needs to be executed.
2) Execute statements directly
# mysql-uroot-p123456-h 192.168.10.210-p 3306 db_logs-e "Select Cdate,uid,clientip,createtime from User_login_log Lim it 1; "
3) Save execution statement to file
# mysql-uroot-p123456-h 192.168.10.210-p 3306 db_logs-e "Select Cdate,uid,clientip,createtime from User_login_log Lim it 1; " > Log.txt
# Cat Log.txt
You can see that the saved result is \ t delimited.
4) Save the execution statement to the file and use awk to replace \ t into a comma# mysql-uroot-p123456-h 192.168.10.210-p 3306 db_logs-e "Select Cdate,uid,clientip,createtime from User_login_log Lim It 1; "| awk ' {print $ ', ', $ $ ', ' $ $ ', ' $4} ' > Log.csv
# Cat Log.csv
MYSQL-E and awk to export CSV files together