What is the size of column of int(11)
in mysql in bytes?
And Maximum value that can be stored in this columns?
INT − A normal-sized integer that can be signed or unsigned. If signed, the allowable range is from -2147483648 to 2147483647. If unsigned, the allowable range is from 0 to 4294967295. You can specify a width of up to 11 digits.
INT(10) means you probably defined it as INT UNSIGNED . So, you can store numbers from 0 up to 4294967295 (note that the maximum value has 10 digits, so MySQL automatically added the (10) in the column definition which (10) is just a format hint and nothing more.
To check the sizes of all of your databases, at the mysql> prompt type the following command: Copy SELECT table_schema AS "Database", ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)" FROM information_schema.
An INT
will always be 4 bytes no matter what length is specified.
TINYINT
= 1 byte (8 bit)SMALLINT
= 2 bytes (16 bit)MEDIUMINT
= 3 bytes (24 bit)INT
= 4 bytes (32 bit)BIGINT
= 8 bytes (64 bit).The length just specifies how many characters to pad when selecting data with the mysql command line client. 12345 stored as int(3)
will still show as 12345, but if it was stored as int(10)
it would still display as 12345, but you would have the option to pad the first five digits. For example, if you added ZEROFILL
it would display as 0000012345.
... and the maximum value will be 2147483647 (Signed) or 4294967295 (Unsigned)
INT(x) will make difference only in term of display, that is to show the number in x digits, and not restricted to 11. You pair it using ZEROFILL
, which will prepend the zeros until it matches your length.
So, for any number of x in INT(x)
ZEROFILL
will prepend zeros.INT(5) ZEROFILL with the stored value of 32 will show 00032
INT(5) with the stored value of 32 will show 32
INT with the stored value of 32 will show 32
INT(3) ZEROFILL with the stored value of 250000 will show 250000
INT(3) with the stored value of 250000 will show 250000
INT with the stored value of 250000 will show 250000
The actual value stored in database is not affected, the size is still the same, and any calculation will behave normally.
This also applies to BIGINT
, MEDIUMINT
, SMALLINT
, and TINYINT
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With