Home >Database >Mysql Tutorial >mysql implements query results export to csv file and import csv file to database operation_Mysql
This article mainly introduces the operation of mysql to export csv files of query results and import csv files into the database. It analyzes mysql related database export, import statement usage and operation precautions in the form of examples. Friends in need can refer to the following
The example of this article describes the operation of mysql to export query results to csv files and import csv files into the database. Share it with everyone for your reference, the details are as follows:
mysql query results export csv file:
select logtime, operatingsystem, imei from GameCenterLogs where operatingsystem >= 1 and operatingsystem <=3 group by operatingsystem,imei into outfile '/tmp_logs/tmp.csv' fields TERMINATED BY ',' OPTIONALLY ENCLOSED BY '#' LINES TERMINATED BY '\r\n'
fields TERMINATED BY ','
Set fields The delimiter
OPTIONALLY ENCLOSED BY '#'
If the content of the set field is a string, use '#' to include
LINES TERMINATED BY '\r \n'
Data line separator
Export file content:
1453513680,3,#hello word#\r\n
1453515470,2,#title content#\r\n
mysql command line to import csv files into the database:
load data infile '/tmp_logs/tmp.csv' into table GameCenterDAULogs fields terminated by ',' OPTIONALLY ENCLOSED BY '#' lines terminated by '\r\n'
Possible operating system Differently, the data line separator of the exported csv file is not necessarily \r\n. You can use cat -A /tmp_logs/tmp.csv
to view the ending character
The above is the detailed content of mysql implements query results export to csv file and import csv file to database operation_Mysql. For more information, please follow other related articles on the PHP Chinese website!