MySQL has a CSV engine that can be used to import data from CSV into a MySQL database faster than a batch program written in PHP or Python.
Examples of specific implementation code:
Copy CodeThe code is as follows:
Load data infile '/tmp/file.csv ' into table _tablename (set character UTF8)
Fields terminated by ', '
Enclosed by ' "'
Lines terminated by ' \ r \ n ';
Some of the keywords involved in this code are explained as follows:
Field terminated by ': This indicates the delimiter in the CSV file, which is the separator between the data;
Enclosed by ': indicates an envelope character;
Lines terminated by ': means line terminator
The CSV format is described in detail in the CSV document (RFC4180), with the following key points:
(1) between the fields with "," (comma) interval, the data rows are separated by \ r \ n;
(2) The string is surrounded by a half-width double quotation mark, and the string itself is represented by a double quotation mark in two double quotes.
With the above explanation, the data import code should be better understood in detail.
Similarly, CSV data can be imported into MySQL database, MySQL data table can also export CSV file, exported code example:
Copy CodeThe code is as follows:
SELECT * FROM tablename to outfile '/tmp/data.txt '
Fields terminated by ', '
Optionally enclosed by ' "'
Lines terminated by ' \ n ';
When you export data from a database to a file and then import the data into a database, you must follow the format defined in the exported file.
http://www.bkjia.com/PHPjc/327962.html www.bkjia.com true http://www.bkjia.com/PHPjc/327962.html techarticle MySQL has a CSV engine that can be used to import data from CSV into a MySQL database faster than a batch program written in PHP or Python. Specific ...