How to parse CSV data into MySQL _php tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.