0
Thanks

A few words of thanks would be greatly appreciated.

MySQL - Loading a text file into ue table



  • To load a text file, perform as follow:


$ tail /home/user1/test.txt 
   'name1',1,9 
   'name2',2,3 
   'name3',3,54 
   'name4',4,2 
   'name5',5,9 
  • In a table defined as follows:


CREATE TABLE chargertest ( 
                prim_key int(11) NOT NULL auto_increment, 
                name varchar(20), 
                x integer, 
                y integer, 
                z timestamp(14), 
                Constraint pk_chargertest PRIMARY KEY  (prim_key) 
);  
  • Note that the 'z' is not defined in the text file and the separator is','.


mysql> load data infile '/home/user1/test.txt' into table chargertest fields terminated by ',' (name,x,y);
0
Thanks

A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jeff Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.
This document, titled "MySQL - Loading a text file into ue table," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (https://ccm.net/).

0 Comments