LOAD DATA 指定格式

  1. 依照檔案 /tmp/animals1.txt 的格式匯入,分隔符號為逗號,字串以雙引號括起來,換行符號 ^M
    [root@kvm8 ~]# cat -EvT /tmp/animals1.txt 
    "2","cat","4"^M$
    "3","chicken","2"^M$
    "1","dog","4"^M$
    
  2. 依照檔案 /tmp/animals1.txt 的格式匯入,分隔符號為逗號,字串以雙引號括起來,換行符號 ^M
    mysql> load data local infile '/tmp/animals1.txt' into table animals 
        -> fields terminated by ',' 
        -> enclosed by '"' 
        -> lines terminated by '\r\n';
    
  3. 再查看資料表 animals 又出現三筆重複的紀錄。
    mysql> select * from animals;
    id	name	foot
    2	cat	4
    3	chicken	2
    1	dog	4
    2	cat	4
    3	chicken	2
    1	dog	4
    2	cat	4
    3	chicken	2
    1	dog	4
    mysql>