MySQL #1264 超出范围值修复?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6621530/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
#1264 Out of range value fix?
提问by Guapo
When I try to insert the below into my MySQL
当我尝试将以下内容插入我的 MySQL 时
INSERT INTO `rooms` (`id`, `ip`) VALUES ('131213', '-259857341');
I fails with the follow error:
我失败并出现以下错误:
Warning: #1264 Out of range value for column 'ip' at row 1
I am looking around but haven't found how to fix or work it out...
我环顾四周,但还没有找到如何修复或解决它...
My field is unsigned intwhich should work just fine for that entry.
我的字段是 unsigned int应该可以很好地用于该条目。
What is the problem and how do I solve ?
有什么问题,我该如何解决?
I am using unsigned int because I wanted to store ips using inet_ntoa/aton.
我使用 unsigned int 是因为我想使用 inet_ntoa/aton 存储 ips。
EDIT:
编辑:
I am using unsigned INT as recommend in MySQL website:
我在 MySQL 网站上推荐使用 unsigned INT:
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”.
要存储由 INET_ATON() 生成的值,请使用 INT UNSIGNED 列而不是带符号的 INT。如果使用带符号的列,则无法正确存储与第一个八位字节大于 127 的 IP 地址对应的值。请参见第 10.6 节“超出范围和溢出处理”。
http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html
http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html
回答by Flimzy
A negative number is out of range for an UNSIGNEDINT. Read the documentationfor a full list of allowed values for a given data type.
负数超出了UNSIGNEDINT的范围。阅读文档以获取给定数据类型允许值的完整列表。
回答by Karolis
Unsigned integer means non-negative value at least.
无符号整数至少意味着非负值。
Not sure if this is what you need but you can try to convert signed integer to 4 bytes unsigned integer as your ipconverter does (http://www.silisoftware.com/tools/ipconverter.php):
不确定这是否是您需要的,但您可以尝试将有符号整数转换为 4 字节无符号整数,就像您的 ipconverter 一样(http://www.silisoftware.com/tools/ipconverter.php):
INSERT INTO `rooms` (`id`, `ip`) VALUES ('131213', '-259857341' & 0xffffffff);
回答by Avada Kedavra
Firstly, by definition, you cannot insert a negative number into a unsigned int
field. Change the field to int
instead (or if possible use non-negative numbers).
首先,根据定义,您不能在unsigned int
字段中插入负数。将该字段更改为int
(或如果可能,使用非负数)。
Secondly i think that you should remove the single-quotes around the inserted number to that the the value is treated as an int
and not a string
.
其次,我认为您应该删除插入数字周围的单引号,以便将该值视为 anint
而不是 a string
。
回答by Mabood Ahmad
Change your INT field into BIGINT and it will work for me smoothly.
将您的 INT 字段更改为 BIGINT,它会顺利地为我工作。