mysql has its own csv engine, which can be used to import data in csv into the mysql database, and the speed is much faster than batch processing programs written in php or python.
Specific implementation code example:
Copy code The code is as follows:
load data infile '/tmp/file.csv' into table _tablename (set character utf8)
fields terminated by ','
enclosed by '"'
lines terminated by 'rn';
Some keywords involved in this code are explained as follows:
fields terminated by '': This indicates the field terminator in the csv file, which is the separator between data;
enclosed by '': indicates the envelope character;
lines terminated by '': refers to the line terminator
The csv format is introduced in detail in the csv document (RFC4180). The key points are:
(1) Fields are separated by "," (comma), and data lines are separated by rn;
(2) The string is surrounded by half-width double quotes, and the double quotes of the string itself are
Through the above explanation, you should have a better understanding of the data import code.
Similarly, csv data can be imported into the mysql database, and the data table in mysql can also be imported. Export csv file, exported code example:
Copy code The code is as follows:
select * from tablename into outfile '/tmp /data.txt'
fields terminated by ','
optionally enclosed by '"'
lines terminated by 'n';
When exporting data in the database to After the file is exported, to import the data into the database, the format defined in the exported file must be adhered to.
http://www.bkjia.com/PHPjc/327962.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327962.htmlTechArticlemysql has its own csv engine, which can be used to import data in csv into the mysql database. And the speed is much faster than batch programs written in php or python. Specifically...