# Difference between mysqlint (m) and int (m) _ MySQL

Source: Internet
Author: User
It is estimated that most of my friends who are getting started with mysql will have this question: what does the number in int (M) mean? According to the relevant information, I summarized the following: int (M) zerofill. after zerofill is added, M will show a little effect, such as int (3) zerofill, most of your friends who are getting started with mysql will have this question: what does the value in int (M) mean?

According to the relevant information, we summarized the following:

Int (M) zerofill. after zerofill is added, M will show a little effect. for example, if int (3) zerofill is inserted into the database as 10, it will be inserted as 010, that is, add a 0. if int (3) and int (10) do not add zerofill, there is no difference between them. M is not used to limit the number of int. the maximum and minimum values of int (M) are related to undesigned values.

Mysql> create table table_one (t int (3) zerofill );
Query OK, 0 rows affected (0.00 sec)

Mysql> insert into table_one set t = 8;
Query OK, 1 row affected (0.00 sec)

Mysql> select * from table_one;
+ -- +
| T |
+ -- +
| 008 |
+ -- +
1 row in set (0.11 sec)

Zerofill with default width, the same as int (10 ):

Mysql> create table table_two (t int zerofill );
Query OK, 0 rows affected (0.02 sec)

Mysql> insert into table_two set t = 10;
Query OK, 1 row affected (0.02 sec)

Mysql> select * from t;
+ ---- +
| T |
+ ---- +
| 1, 0000000010 |
+ ---- +
1 row in set (0.08 sec)

Without zerofill:

Mysql> create table table_3 (t int );
Query OK, 0 rows affected (0.01 sec)

Mysql> insert into table_3 set t = 10;
Query OK, 1 row affected (0.01 sec)

Mysql> select * from t;
+ -- +
| T |
+ -- +
| 10 |
+ -- +

1 row in set (0.00 sec)

1 bytes = 8 bit. The maximum length of a byte can be 2 to the power of 8. 11111111 is also in the computer.

-128 to 127

1. BIT [M]

Bit field type. M indicates the number of digits of each value, ranging from 1 to 64. if M is ignored, the default value is 1.

2. TINYINT [(M)] [UNSIGNED] [ZEROFILL] M is 4 by default

A small integer. The signed range is-128 to 127. The unsigned range is 0 to 255.

3. BOOL, BOOLEAN

Is a synonym for TINYINT (1. The zero value is considered false. The non-zero value is true.

4. SMALLINT [(M)] [UNSIGNED] [ZEROFILL] M is 6 by default

A small integer. The signed range is-32768 to 32767. The unsigned range is 0 to 65535.

5. MEDIUMINT [(M)] [UNSIGNED] [ZEROFILL] M is 9 by default

An integer of medium size. The signed range is-8388608 to 8388607. The unsigned range is 0 to 16777215.

6. INT [(M)] [UNSIGNED] [ZEROFILL] M is 11 by default

An integer of the normal size. The signed range is-2147483648 to 2147483647. The unsigned range is 0 to 4294967295.

7. BIGINT [(M)] [UNSIGNED] [ZEROFILL] M is 20 by default

A large integer. The signed range is-9223372036854775808 to 9223372036854775807. The unsigned range is 0 to 18446744073709551615.

*: Here M represents not the specific length stored in the database.

In fact, when we select the int type, whether it is int (3) or int (11), it stores 4 bytes in the database, when int (3) is used, if you input 10, the storage space 010 will be provided by default. that is to say, this 3 represents the default length, when you have less than three places, it will not help you. when you have more than three places, there will be no impact.

The day before yesterday, the group administrator asked me what is the difference between int (10) and int (11). I thought it was the difference in length. now, there is no difference between them in terms of storage. Int (10) can also represent the value of 2147483647 int (11.

We usually do not add this option when creating databases, so there is no difference between them.

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.