How do MySQL import the csv format data file solution

  • 2020-05-14 05:06:23
  • OfStack

To do their own backup, masters please ignore.
The data is too big, use the database client software to import the special card directly, or directly execute SQL.
1. Specify the file path.
2. Fields are separated by commas and data lines are separated by \r\n (I have files separated by \n).
3. The string is surrounded by half-corner double quotation marks, and the double quotation marks of the string itself are represented by two double quotation marks.

Sql code

 
load data infile 'D:\\top-1m.csv' 
into table `site` 
fields terminated by ',' optionally enclosed by '"' escaped by '"' 
lines terminated by '\n'; 

Backup an export as well.
Sql code
 
select * from `site` 
into outfile 'D:\\top-1m.csv' 
fields terminated by ',' optionally enclosed by '"' escaped by '"' 
lines terminated by '\n'; 


Related articles: