This article mainly introduces the MySQL implementation query results export CSV file and import CSV file to the database operation, combined with instance form analysis of MySQL related database export, import statements using methods and operational considerations, the need for friends can refer to the next
This article describes the MySQL implementation query results export CSV file and import CSV file to the database operation. Share to everyone for your reference, as follows:
MySQL Query results export CSV file:
Select LogTime, OperatingSystem, Imeifrom gamecenterlogswhere operatingsystem >= 1 and OperatingSystem <= 3group by Operatingsystem,imeiinto outfile '/tmp_logs/tmp.csv ' fields TERMINATED by ', ' optionally enclosed by ' # ' LINES TE rminated by ' \ r \ n '
fields TERMINATED BY ','
Set the separator for a field
OPTIONALLY ENCLOSED BY '#'
Set the field contents to be a string, use ' # ' contains
LINES TERMINATED BY '\r\n'
Data row Separator
Export File Contents:
1453513680,3, #hello word#\r\n
1453515470,2, #title content#\r\n
MySQL command line import CSV file to database:
Load data infile '/tmp_logs/tmp.csv ' into table gamecenterdaulogs fields terminated by ', ' optionally enclosed by ' # ' lines Terminated by ' \ r \ n '
There may be different operating systems, the data row delimiter for the exported CSV file is not necessarily \ r \ n, you can use the cat -A /tmp_logs/tmp.csv
view end character