Mysql: Loading data from file
Loading Data into Tables from Text Files.
Assume you have the following table.
CREATE TABLE loadtest (
pkey int(11) NOT NULL auto\_increment,
name varchar(20),
exam int,
score int,
timeEnter timestamp(14),
PRIMARY KEY (pkey)
);
$ tail /tmp/out.txt
'name22999990',2,94
'name22999991',3,93
'name22999992',0,91
'name22999993',1,93
'name22999994',2,90
'name22999995',3,93
'name22999996',0,93
'name22999997',1,89
'name22999998',2,85
'name22999999',3,88
NOTE: loadtest contains the "pkey" and "timeEnter" fields which are not
present in the "/tmp/out.txt" file. Therefore, to successfully load
the specific fields issue the following:
mysql> load data infile '/tmp/out.txt' into table loadtest
fields terminated by ',' (name,exam,score);