Demand:
1. Execute the results of a SQL;
2. Export the results to a CSV file;
3. Execute through the command line;
- db_name - host_name - user_name - - -E "select*from| ' s/\t/","/g;s/^/"/;s/$/"/;s/\n//g ' > apps.csv
Sed part of the content can be omitted (specific parameters I still do not understand, the effect is to set the CSV file delimiter, etc.)
-a specifies the database;
-h specifies IP, remote database needs, export Local database can be omitted;
-u user name;
-p password;
-SS Specifies whether the exported result contains a column name;
-E followed by SQL statement (execute);
The simple wording is as follows:
- db_name - host_name - user_name -P -E "select*from> apps.csv
Attention:
In the assumption that SQL contains keywords, under Windows can refer to the use of MySQL, plus "[tab], such as:
SELECT 'key from 'order';
But under Linux you need to escape the ' [tab] ', using ' \ ', as follows:
SELECT \ 'key from \ 'order\ ';
Complete as follows:
- db_name - host_name - user_name -P -E "select \ 'key from \ 'order100 > apps.csv
Reference: https://www.cnblogs.com/wuhongkuan/p/4704299.html
MySQL export SQL execution results to a CSV file