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