Uploading csv file using filters

前端 未结 1 810
时光说笑
时光说笑 2021-01-29 09:03

Am trying to upload CSV data to MYSQL table using the below query.It\'s running successfully. The CSV file having 20 million data. But still now I have a problem to upload the d

1条回答
  •  生来不讨喜
    2021-01-29 09:56

    I guess your command is working fine but filling your table with 4 rows instead of the expected 2.

    LOAD DATA IN FILE documentation seem not to support what you are asking for, it can only exclude line by number, so if you have a way to know the line numbers while creating this csv file you could use this feature. Otherwise there are 2 workarounds:

    You can filter your file before loading it (outside of mysql) with (on Linux)

    grep "D$" /root/782012_23.csv > filteredfile; LOAD DATA LOCAL INFILE 'filteredfile' ...
    

    or filter after the loading via SQL:

    your_command;mysql -u user -ppassword "DELETE FROM yourtable WHERE DND = 'A'";
    

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