MySQL uses the delimiter to import and export data

Source: Internet
Author: User

MySQL uses the delimiter to import and export records and summarizes the Syntax: Backup:

SELECT INTO OUTFILESELECT * FROM hx_9enjoy INTO OUTFILE '/tmp/9enjoy.txt'

 

By default, fields are separated by tab, and records are separated by \ n. You can customize three parameters.
SELECT * FROM hx_9enjoy INTO OUTFILE '/tmp/9enjoy_hx.txt' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n';

 

That is, use, split field, double quotation marks limit field content, \ n split record. You can also specify the record output for certain conditions:
SELECT * FROM hx_9enjoy WHERE id < 100 INTO OUTFILE '/tmp/9enjoy_100.txt'

 

Restore:
LOAD DATA INFILE

 

Default:
LOAD DATA INFILE '/tmp/9enjoy.txt' INTO TABLE hx_9enjoy

 

If a Delimiter is specified, the Delimiter is added:
LOAD DATA INFILE '/tmp/9enjoy.txt' INTO TABLE hx_9enjoy FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n'

 

Note 1. mysql must have the permission to access the directory where the file is generated. 2. For security reasons, the existing file cannot be overwritten, no matter how permissions are assigned to the file. 3. You cannot export a compressed file directly.

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.