MySQL commonly used data types are numeric type, text type, binary type, and time date.
1. Numeric type
Data type |
Description |
BIT (M) |
Bit type. m specified number of bits, default value 1, Range 1-64 |
TINYINT [Unsigned][zerofill] |
The signed range is-128-127. unsigned 0-255 |
Bool,boolean |
Use 0 or 1 to indicate true or false |
SMALLINT [Unsigned][zerofill] |
2 of the 16-time Square |
INT [Unsigned][zerofill] |
2 of the 32-time Square |
BIGINT [Unsigned][zerofill] |
2 of the 64-time Square |
Floar (M,D) [Unsigned][zerofill] |
m specifies the display length, d refers to the number of decimal digits |
DOUBLE (M,D) [Unsigned][zerofill] |
A decimal that represents a greater precision than float |
2. Text type
Data type |
Description |
CHAR (size) |
Fixed-length strings |
VARCHAR (size) |
Variable-length strings |
TEXT (CLOB) |
Large text |
Example:
Create Table Student ( int, varchar) ,Char( - ));
In the above example, the type of name is varchar. When the input character length is less than 20 o'clock, the name is less than 20, and when the input character length is greater than 20 o'clock, an error is entered.
Class is of type char and has a length of 20 and an error when the input length is greater than 20 o'clock.
There are altogether four types of text
Type |
Memory size |
Tinytext |
255B |
TEXT |
64K (Common) |
Mediumtext |
16M |
Longtext |
4G |
3. Binary type
Type |
Description |
Blob |
Used to store binary data such as Picture/music |
Four types of BLOBs
Type |
Memory size |
Tinyblob |
255B |
Blob |
34. |
Mediumblob |
16M |
Longblob |
4G |
4. Time and Date type
Type |
Description |
DATE |
Expression range: ' 1000-1-1 ' to ' 9999-12-31 ' 3 bytes |
Datetime |
Indication range: ' 1000-1-1 00:00:00 ' to ' 9999-12-31 23:59:59 ' 8 bytes |
TIMESTAMP |
Timestamp, which can be used to automatically record the time of INSERT, update operation |
MySQL Common data types