MYSQL import data from csv using LOAD DATA INFILE

前端 未结 11 1423
感动是毒
感动是毒 2020-11-22 09:12

I am importing some data of 20000 rows from a CSV file into Mysql.

Columns in the CSV are in a different order than MySQL table\'s columns. How to automatically assi

11条回答
  •  抹茶落季
    2020-11-22 09:51

    You can load data from a csv or text file. If you have a text file with records from a table, you can load those records within the table. For example if you have a text file, where each row is a record with the values for each column, you can load the records this way.

    table.sql

    id //field 1
    
    name //field2
    

    table.txt

    1,peter
    
    2,daniel
    
    ...
    

    --example on windows

    LOAD DATA LOCAL INFILE 'C:\\directory_example\\table.txt'
    INTO TABLE Table
    CHARACTER SET UTF8
    FIELDS TERMINATED BY ','
    LINES TERMINATED BY '\r\n'; 
    

提交回复
热议问题