2011-07-08 36 views
1

当我尝试插入下面的进入我的MySQL#1264超出范围值修复?

INSERT INTO `rooms` (`id`, `ip`) VALUES ('131213', '-259857341'); 

我失败,与后续的错误:

Warning: #1264 Out of range value for column 'ip' at row 1 

我环顾四周,但还没有找到如何解决或解决它。 ..

我的字段是无符号int这应该工作得很好,为该条目。

什么问题,我该如何解决?

我使用unsigned int因为我想用inet_ntoa/aton来存储ips。

编辑:

我使用unsigned int类型的建议在MySQL网站:

To store values generated by INET_ATON(), use an INT UNSIGNED column rather than INT, which is signed. If you use a signed column, values corresponding to IP addresses for which the first octet is greater than 127 cannot be stored correctly. See Section 10.6, “Out-of-Range and Overflow Handling”.

http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html

+2

什么是类型提交ip? – JellyBelly

+2

它是在上面的问题;)'我的领域是无符号整数,应该适用于该条目.'因为-259857341不超过最小值和最大值。 – Guapo

+1

int字段有多少个字节?参考:http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html – JellyBelly

回答

1

无符号整数表示至少为非负值。

不知道这是否是你所需要的,但你可以尝试符号整数转换为4个字节的无符号整数作为ipconverter做(http://www.silisoftware.com/tools/ipconverter.php):

INSERT INTO `rooms` (`id`, `ip`) VALUES ('131213', '-259857341' & 0xffffffff); 
5

负数超出范围为UNSIGNED INT。阅读documentation以获取给定数据类型的完整允许值列表。

+0

从MySQL要存储由INET_ATON()生成的值,请使用INT UNSIGNED列而不是经过签名的INT。如果使用带符号列,则与第一个字节大于127的IP地址对应的值无法正确存储。请参见第10.6节“超出范围和溢出处理”。 – Guapo

+3

我并不争辩INT UNSIGNED对于存储IP是有意义的。我只是说它不适合存储负数。而且IP永远不会消极。 – Flimzy

2

首先,顾名思义,你不能插入一个负数字转换为unsigned int字段。改为将字段更改为int(或者如果可能,请使用非负数)。

其次,我认为你应该删除插入数字周围的单引号,该值被视为int而不是string

0

将您的INT字段更改为BIGINT,它对我来说会很顺畅。