Mysql 在 Blob 列的“LOAD DATA LOCAL INFILE”中使用 'SET' 关键字时出现错误 1064
Mysql Error 1064 when using 'SET' keyword in `LOAD DATA LOCAL INFILE` for a blob column
我正在尝试使用 'LOAD DATA LOCAL INFILE' 从文件中插入 table。
我可以插入其他 table,但我遇到了包含 blob 列的 table 的问题。
文件中的 blob 值存储为十六进制值,每列由 ,
个字符分隔。
我正在关注 here
的回答
Mysql服务器版本为5.6.44
这是table定义
CREATE TABLE `tx_bin` (
`hash_id` bigint(20) unsigned NOT NULL,
`block_height` bigint(20) NOT NULL,
`binary` blob NOT NULL,
PRIMARY KEY (`hash_id`, `block_height`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
这是我用来插入 table
的文件中的示例值
4,1,01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0e0420e7494d017f062f503253482fffffffff0100f2052a010000002321021aeaf2f8638a129a3156fbe7e5ef635226b0bafd495ff03afe2c843d7e3a4b51ac00000000
7,2,01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0e0432e7494d010e062f503253482fffffffff0100f2052a010000002321038a7f6ef1c8ca0c588aa53fa860128077c9e6c11e6830f4d7ee4e763a56b7718fac00000000
10,3,01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0e0486e7494d0151062f503253482fffffffff0100f2052a01000000232103f6d9ff4c12959445ca5549c811683bf9c88e637b222dd2e0311154c4c85cf423ac00000000
这是我使用的语法
LOAD DATA LOCAL INFILE '/work/bootstrap/10000/tx_bin'
INTO TABLE tx_bin FIELDS TERMINATED BY ','
(hash_id,block_height,@bin)
SET binary=UNHEX(@bin);
我遇到的错误
ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near 'binary=UNHEX(@bin)' at line 1
如果我删除 SET binary
则插入成功(但没有二进制数据)。
LOAD DATA LOCAL INFILE '/work/bootstrap/10000/tx_bin'
INTO TABLE tx_bin FIELDS TERMINATED BY ','
(hash_id,block_height,@bin);
然后我尝试使用 SET,但在其他列上,它也成功了。
LOAD DATA LOCAL INFILE '/work/bootstrap/10000/tx_bin'
INTO TABLE tx_bin FIELDS TERMINATED BY ','
(hash_id,@height,@bin)
SET block_height=@height;
如果我在其他列之后再次添加 blob 列,它也会给我同样的错误
LOAD DATA LOCAL INFILE '/work/bootstrap/10000/tx_bin'
INTO TABLE tx_bin FIELDS TERMINATED BY ','
(hash_id,@height,@bin)
SET block_height=@height, binary=UNHEX(@bin);
知道我做错了什么吗?
BINARY
是MySQL中的reserved word,作为字段名时需要加引号。
LOAD DATA LOCAL INFILE '/work/bootstrap/10000/tx_bin'
INTO TABLE tx_bin FIELDS TERMINATED BY ','
(hash_id,block_height,@bin)
SET `binary`=UNHEX(@bin);
我正在尝试使用 'LOAD DATA LOCAL INFILE' 从文件中插入 table。 我可以插入其他 table,但我遇到了包含 blob 列的 table 的问题。
文件中的 blob 值存储为十六进制值,每列由 ,
个字符分隔。
我正在关注 here
的回答Mysql服务器版本为5.6.44
这是table定义
CREATE TABLE `tx_bin` (
`hash_id` bigint(20) unsigned NOT NULL,
`block_height` bigint(20) NOT NULL,
`binary` blob NOT NULL,
PRIMARY KEY (`hash_id`, `block_height`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
这是我用来插入 table
的文件中的示例值4,1,01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0e0420e7494d017f062f503253482fffffffff0100f2052a010000002321021aeaf2f8638a129a3156fbe7e5ef635226b0bafd495ff03afe2c843d7e3a4b51ac00000000
7,2,01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0e0432e7494d010e062f503253482fffffffff0100f2052a010000002321038a7f6ef1c8ca0c588aa53fa860128077c9e6c11e6830f4d7ee4e763a56b7718fac00000000
10,3,01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0e0486e7494d0151062f503253482fffffffff0100f2052a01000000232103f6d9ff4c12959445ca5549c811683bf9c88e637b222dd2e0311154c4c85cf423ac00000000
这是我使用的语法
LOAD DATA LOCAL INFILE '/work/bootstrap/10000/tx_bin'
INTO TABLE tx_bin FIELDS TERMINATED BY ','
(hash_id,block_height,@bin)
SET binary=UNHEX(@bin);
我遇到的错误
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'binary=UNHEX(@bin)' at line 1
如果我删除 SET binary
则插入成功(但没有二进制数据)。
LOAD DATA LOCAL INFILE '/work/bootstrap/10000/tx_bin'
INTO TABLE tx_bin FIELDS TERMINATED BY ','
(hash_id,block_height,@bin);
然后我尝试使用 SET,但在其他列上,它也成功了。
LOAD DATA LOCAL INFILE '/work/bootstrap/10000/tx_bin'
INTO TABLE tx_bin FIELDS TERMINATED BY ','
(hash_id,@height,@bin)
SET block_height=@height;
如果我在其他列之后再次添加 blob 列,它也会给我同样的错误
LOAD DATA LOCAL INFILE '/work/bootstrap/10000/tx_bin'
INTO TABLE tx_bin FIELDS TERMINATED BY ','
(hash_id,@height,@bin)
SET block_height=@height, binary=UNHEX(@bin);
知道我做错了什么吗?
BINARY
是MySQL中的reserved word,作为字段名时需要加引号。
LOAD DATA LOCAL INFILE '/work/bootstrap/10000/tx_bin'
INTO TABLE tx_bin FIELDS TERMINATED BY ','
(hash_id,block_height,@bin)
SET `binary`=UNHEX(@bin);