How do I read this text file and Insert into MySQL?

前端 未结 5 710
萌比男神i
萌比男神i 2020-12-18 16:07

sample

user id  User Name
   U456      Mathew 
   U457      Leon
   U458      Cris
   U459      Yancy
   U460      Jane

and so on up to 500

5条回答
  •  醉话见心
    2020-12-18 16:49

    LOAD DATA INFILE

    Example:

    NOTE: if you run this from Windows you need to escape the forward slashes in the file path.

    EXAMPLE:

    C:\\path\to\file.txt
    

    Looks like:

    C:\\\\path\\to\\file.txt
    

    Here is the query:

    LOAD DATA INFILE '/path/to/sample.txt' 
    INTO TABLE `database_name`.`table_name` 
    FIELDS TERMINATED BY ','
    LINES TERMINATED BY '\r\n'
    IGNORE 1 LINES
    (
    user_id, user_name
    )
    

提交回复
热议问题