MYSQL 中 int(11) 数据类型面临的问题
我在 MYSQL 中有一个表,其主键 id int(11) (自动递增)。现在我有一个程序可以读取一些文本文件并在 id 列中输入值。 所以我的表应该包含:
id
897413
791783
但发生的情况是,我在表中找不到大数字。这是因为 int(11) 可以容纳的最大值吗?将 int(11) 增加到 int(20) 仍然面临同样的问题。我无法将数据类型更改为 big int,因为我已经实现了很多代码。
编辑: 我尝试插入一条 id 为 523826 的记录,它在数据库中保存为 450258。为什么会这样?
I have a table in MYSQL in with a primary key id int(11) (auto-incremented). Now I have a program which reads some text file and enters the value in id column.
So my table should contains :
id
897413
791783
But what happens is that, I can't find big numbers in my table. Is this because of maximum value that int(11) can hold? Increased int(11) to int(20) still facing same problem. I can't change the datatype to big int as I have already implemented a lot of code.
EDIT:
I tried to insert a single record with id as 523826 and it got saved in DB as 450258. Why so?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
的 mysql 手册 中的定义int
数据类型:int
类型始终为 4 字节(32 位)。int(11)
中的11
只是“显示宽度”,仅对UNSIGNED ZEROFILL
列重要。有关更多详细信息,请参阅此博文。Definition from mysql manual for the
int
data type:The
int
type is always 4 bytes (32 bits). The11
inint(11)
is just the "display width", that only matters forUNSIGNED ZEROFILL
columns. More details on this blog post.MySQL中的INT是32位。 INT(11) 可能意味着您有一个签名的 INT,这对于 ID 来说是无用的。将其更改为无符号 INT 会自动使可用 ID 数量加倍(因为没有人使用负 ID)。尽管 11 “看起来”更大,但这是因为它考虑了数字的“长度”,如果它是最大负数 (-2147483648),即 11 个字符长。
BIGINT 最多可以支持 64 位,有符号或无符号。同样,无符号将允许您使用两倍的 ID (>0)。
正如 Andrew 上面提到的,如果您的 PHP 不支持 64 位整数,那么您将无法轻松使用它们。
希望有帮助。
INT in MySQL is 32 bits. INT(11) likely means you have a signed INT, which for an ID is useless. Changing it to an unsigned INT will automatically double the number of IDs available (since nobody uses a negative ID). Even though 11 "seems" bigger, it's because it takes into consideration the "length" of the number if it's the maximum negative number (-2147483648) which is 11 characters long.
BIGINT will let you go up to 64 bits, signed or unsigned. Again, unsigned will allow you twice as many IDs (>0).
As Andrew mentioned above, if your PHP does not support 64 bit integers then you will not be able to easily use them.
Hope that helps.