MySQL Import CSV file

Source: Internet
Author: User
Tags mysql version mysql import

mysql> Load Data local infile '/root/bao/pingtaizhangwumingxi/20170206_zwmx-pt-rmb_297308.csv ' into table platform_ Billing_details fields TERMINATED by ', ' LINES TERMINATED by ' \ r \ n ' Ignore 1 LINES;

Linux uses shell scripts to bulk import CSV files to MySQL database

Prerequisite: The first behavior field name for each CSV file

database field name created with the field name of the CSV file

1. Batch import of multiple CSV files

For file in./*.csv;do mv $file tablename.csv;mysqlimport--local--fields-terminated-by= ","-uusename-ppassword databas Ename TABLENAME.CSV;RM Tablename.csv;done

(The script will delete the files while importing the data don't forget to back up the files before importing the database.)

2. Import a CSV file

MySQL--local-infile-uusename-ppassword databasename-e "LOAD DATA local infile ' 1.csv ' into TABLE tablename inated by ', ' LINES TERMINATED by ' \ r \ n ' "

(', ' and ' \ r \ n ' are based on your CSV file, the first one is the field segmentation flag, the second is the line split flag)

(--local-infile: No this will error "error 1148 (42000) at line 1:the used command was not allowed with this MySQL version")

MySQL Import CSV file

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.