开发者

Issues faced with int(11) datatype in MYSQL

开发者 https://www.devze.com 2023-03-27 16:11 出处:网络
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.

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 :

开发者_如何学C
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?


Definition from mysql manual for the int data type:

A normal-size integer. The signed range is -2147483648 to 2147483647. The unsigned range is 0 to 4294967295.

The int type is always 4 bytes (32 bits). The 11 in int(11) is just the "display width", that only matters for UNSIGNED ZEROFILL columns. More details on this blog post.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号