MySQL data type int (M) What does that mean?

Source: Internet
Author: User
Tags mysql manual

The integer types in the MySQL data type is a bit odd. You may see int data types such as int (3), int (4), int (8). When I first contacted MySQL, I thought that int (3) occupies less storage space than int (4), and int (4) occupies less storage space than int (8).

Later, see the MySQL manual, found that they understand the wrong.

The code is as follows Copy Code

Int (m): M indicates the maximum display width for the integer types.

In the integer data type, M represents the maximum display width.


Originally, in Int (m), the value of M has nothing to do with how much storage space the Int (m) occupies. Int (3), int (4), int (8) are occupied by 4 Btyes of storage space on the disk. In other terms, int (M) is the same as the int data type, except that the way it is displayed to the user is somewhat different.

In addition, int (M) can only be combined with Zerofill to make us see the difference clearly.

The code is as follows Copy Code

Mysql> drop table if exists t;
Mysql> CREATE TABLE t (id int zerofill);
mysql> INSERT into T (ID) values (10);

Mysql> select * from T;
+------------+
| ID |
+------------+
| 0000000010 |
+------------+

Mysql> ALTER TABLE t change column ID ID int (3) Zerofill;

Mysql> select * from T;
+------+
| ID |
+------+
| 010 |
+------+

Mysql>
Mysql> ALTER TABLE t change column ID ID int (4) Zerofill;

Mysql> select * from T;
+------+
| ID |
+------+
| 0010 |
+------+

Mysql>
mysql> INSERT into T (ID) values (1000000);

Mysql> select * from T;
+---------+
| ID |
+---------+
| 0010 |
| 1000000 |
+---------+

As you can see from the test above, "(M)" Specifies the width of the int type value display. If the field data type is int (4), then: When the value 10 o'clock is displayed, "00" is to be added to the left, and "0" on the left when the number 100 is displayed, and when the number 1000000 is displayed, The specified width "(4)" has been exceeded, so it is output as is.

When using the integer type in the MySQL data type (tinyint, smallint, mediumint, Int/integer, bigint), I can't think of any meaning when you add a "(M)" to the data type after the special requirement.

Add the following data types

1. Integral type

MySQL data type Meaning (Signed)
tinyint (m) 1 byte range ( -128~127)
smallint (m) 2 byte range ( -32768~32767)
Mediumint (M) 3 byte range ( -8388608~8388607)
Int (m) 4 byte range ( -2147483648~2147483647)
BigInt (M) 8 byte Range (18 +-9.22*10 of the second party)


The value range, if added unsigned, doubles the maximum value, such as tinyint unsigned (0~256).

The M in Int (m) represents the width of the display in the Select query result set, does not affect the actual range of values, does not affect the width of the display, and does not know what is the use of this m.

2. Floating-point type (float and double)

MySQL data type Meaning
Float (m,d) Single-precision floating-point 8-bit precision (4 bytes) m total number, D decimal places
Double (m,d) Double-precision floating-point 16-bit precision (8 bytes) m total number, D decimal places


Set a field defined as float (5,3), if you insert a number 123.45678, the actual database is 123.457, but the total number is also the actual, that is 6 bits.

3, fixed-point number

A floating-point type holds an approximate value in the database, while a fixed-point type holds an exact value in the database.

The decimal (m,d) parameter m<65 is the total number, d<30 and d<m are decimal places.

4, String (Char,varchar,_text)

MySQL data type Meaning
CHAR (n) Fixed length, up to 255 characters
VARCHAR (n) Fixed length, up to 65,535 characters
Tinytext Variable length, up to 255 characters
Text Variable length, up to 65,535 characters
Mediumtext Variable length, up to 2 of 24 square-1 characters
Longtext Variable length, up to 2 of 32 square-1 characters

Related Article

Contact Us

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.