Import hex/binary data into mysql

前端 未结 2 1273
闹比i
闹比i 2020-12-29 12:03

I need to import into a mysql server (5.5) a set of large data having one field as a blob. Following the samples of SELECT INTO OUTFILE and LOAD DATA INFILE, it works [almos

相关标签:
2条回答
  • 2020-12-29 12:27

    You can use the SET part of LOAD DATA INFILE, and you don't need the 0x escaping stuff:

    1, 1, 123456FF
    2, 1, aabbcc
    3, 1, ddeeff
    

    And then you assign the column to a variable, and then set the column to the UNHEXed version of that variable:

    LOAD DATA INFILE 'file' INTO TABLE `table` (column1, column2, @var1)
    SET column3 = UNHEX(@var1)
    
    0 讨论(0)
  • 2020-12-29 12:43

    Couldn't find any alternative. It looks like the only way is the binary one (also, there is already a bug/feature-request on mysql regarding this).

    Two things to consider:

    • text-file encoding when generating the input file;
    • character escaping (NEW-LINE, TAB, QUOTE, etc);
    0 讨论(0)
提交回复
热议问题