Import hex/binary data into mysql

空扰寡人 提交于 2019-11-30 07:27:07

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)

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);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!