我有一个文件,其中包含以非常大的整数表示的 ipv6 地址。当我将它导入mysql时,数据是错误的。为了让加载数据正确地将数据导入二进制(16)列,我需要做什么?
架构:
CREATE TABLE `ipv6_test` (
`ip` binary(16) NOT NULL,
`name` varchar(128) COLLATE utf8_bin DEFAULT NULL,
PRIMARY KEY (`ip`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
要导入的 CSV 文件,ipv6_test.csv:
"58569107296622255421594597096899477505","test"
MySQL导入命令:
mysql> load data local infile 'ipv6_test.csv' into table ipv6_test fields terminated by ',' enclosed by '"' lines terminated by '\n';
询问:
select ip, INET6_NTOA(ip), name from ipv6_test;
不正确的结果:
+------------------+-----------------------------------------+------+
| ip | INET6_NTOA(ip) | name |
+------------------+-----------------------------------------+------+
| 5856910729662225 | 3538:3536:3931:3037:3239:3636:3232:3235 | test |
+------------------+-----------------------------------------+------+
预期成绩:
+------------------+-----------------------------------------+------+
| ip | INET6_NTOA(ip) | name |
+------------------+-----------------------------------------+------+
| ? binary data ? | 2C0F:FFF0:0000:0000:0000:0000:0000:0001 | test |
+------------------+-----------------------------------------+------+