Mysqlimport example mysqlimport-uroot-p123456 test/tmp/mytbl.txt;
Convention: the last part of the file name is the table name. The preceding statement must specify the database when importing data to the mytblmysqlimport table, the above statement database imports csvmysqlimport-uroot-p -- local -- lines-terminated-by = "\ r \ n" -- fields-terminated-by = ", "-- fields-enclosed-by =" \ "" test/tmp/mytbl.csv load data example mysql> load data infile '/tmp/mytbl.txt' into table mytblload data can be left unspecified. statement, mysql must have the read permission of/tmp/to import csvmysql> load data infile '/tmp/mytbl.csv 'into table mytbl fields terminated ', 'enabledby' "'Lines terminated by' \ r \ n' www.2cto.com to process duplicate primary keys and replace existing values mysql> load data infile '/tmp/mytbl.txt' replace into table mytbl fields terminated if the '\ t' lines terminated by' \ n' table already exists, do not import mysql> load data infile '/tmp/mytbl.csv 'ignore into table mytbl fields terminated ', 'enabledby' "'Lines terminated by' \ r \ n' skip the file line. The following example skips the first line of mysql> load data infile'/tmp/mytbl.txt 'into table mytbl ignore 1 linescript pre-processing file data.txt content: date Time Name Weight State2006-09-01 12:00:00 Bill Wills 200 Nevada2006-09-02 09:00:00 Jeff Deft 150 Oklahoma2006-09-04 03:00:00 Bob Hobbs 225 Utah2006-09-07 08:00:00 Hank Banks 175 Texas file must be loaded into the following table create table tbl (dt datetime, last_name char (10), first_name char (10), weight_kg float, st_abbrev char (2) create table states (name varchar (20), shortname char (2 )) name shortnameNevada NVOklahoma OKUtah UTTexas TXinsert into statesvalues ('nevada ', 'nv'), ('oklahoma ',' OK '), ('utah ', 'ut'), ('texas, 'tx ') Import: load data infile'/tmp/data.txt 'into table tblignore 1 lines (@ date, @ time, @ name, @ weight_lb, @ state) set dt = concat (@ date, '', @ time), first_name = substring_index (@ name,'', 1 ), last_name = substring_index (@ name, '',-1), weight_kg = @ weight_lb *. 454, st_abbrev = (select shortname from states where name = @ state); Result: mysql> select * from tbl; certificate + certificate + ----------- + ------------ + ----------- + | dt | last_name | first_name | percent | + percent + ----------- + ------------ + ----------- + | minute 12:00:00 | Wills | bill | 90.8 | NV | 09:00:00 | Deft | Jeff | 68.1 | OK | 03:00:00 | Hobbs | Bob | 102.15 | UT | 08:00:00 | Banks | thank | 79.45 | TX | + --------------------- + ----------- + ------------ + ----------- + import windows Local files to the mysql database in linux, add localload data local infile 'C:/mytbl.txt 'into table mytbl fields terminated by' \ t' lines terminated by '\ r \ n' author stublue