MySQL LOAD DATA INFILE: works, but unpredictable line terminator

前端 未结 7 908
走了就别回头了
走了就别回头了 2020-12-25 14:58

MySQL has a nice CSV import function LOAD DATA INFILE.

I have a large dataset that needs to be imported from CSV on a regular basis, so this feature is

相关标签:
7条回答
  • 2020-12-25 15:44

    I assuming the you need information only through mysql no by any programming language. Before use load data covert the format to windows format \r\n ( CR LF ) if u have notepad++. And then process the Load data query. Make sure the LINES TERMINATED BY '\r\n'

    enter image description here

    Edit:

    Since the editors are often unsuitable for converting larger files. For larger files the following command is often used both windows and linux

    1) To convert into windows format in windows

    TYPE [unix_file] | FIND "" /V > dos_file
    

    2) To convert into windows format in linux

    unix2dos  [file]
    

    The other commands also available

    A windows format file can be converted to Unix format by simply removing all ASCII CR \r characters by tr -d '\r' < inputfile > outputfile

    grep -PL $'\r\n' myfile.txt # show UNIX format  style file (LF terminated)
    grep -Pl $'\r\n' myfile.txt # show WINDOS format style file (CRLF terminated)
    

    In linux/unix the file command detects the type of End-Of-Line (EOL) used. So the file type can be checked using this command

    0 讨论(0)
提交回复
热议问题