Home > Database > Mysql Tutorial > mysql implements query results export to csv file and import csv file to database operation_Mysql

mysql implements query results export to csv file and import csv file to database operation_Mysql

无忌哥哥
Release: 2018-07-12 14:13:06
Original
1650 people have browsed it

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 &#39;/tmp_logs/tmp.csv&#39;
fields TERMINATED BY &#39;,&#39; OPTIONALLY ENCLOSED BY &#39;#&#39; LINES TERMINATED BY &#39;\r\n&#39;
Copy after login

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 &#39;/tmp_logs/tmp.csv&#39;
into table GameCenterDAULogs fields terminated by &#39;,&#39; OPTIONALLY ENCLOSED BY &#39;#&#39; lines terminated by &#39;\r\n&#39;
Copy after login


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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template