About MySQL data types

In MySQL common data types are divided into the following categories: Value, strings, date time type.

Numeric types

String type

Date Time Type

type of data  Byte count  Ranges  format Remark 
 year  1  1901~2155  yyyy  In memory
 date  3  1000-01-01~9999-12-31  yyyy-MM-dd  Store date values
 time  3  -838:59:59~838:59:59  HH:mm:ss  Value storage time (minutes and seconds time)
 datetime  8  1000-01-01 00:00:00~9999-12-31 23:59:59  yyyy-MM-dd HH:mm:ss  Storage date + time
 timestamp  4  1970-01-01 08:00:01~2038-01-19 11:14:07  yyyy-MM-dd HH:mm:ss  Stores the date + time stamp can be used for

drop table if exists test_time;
create table test_time(
    year_value year,
    date_value date,
    time_value time,
    datetime_value datetime,
    timestamp_value timestamp
)engine=innodb default charset=utf8 comment="测试时间表";

mysql> insert into test_time values(now(), now(), now(), now(), now());
mysql> insert into test_time values(2019,20190910,160628,20190910160636,null);

create_time datetime default current_timestamp,
update_time datetime default current_timestamp on update current_timestamp,
create_time timestamp default current_timestamp comment "创建时间",
update_time timestamp default current_timestamp on update current_timestamp comment "修改时间",

Data type (data_type) system refers to the type of data allowed.

Each column in the database should have the appropriate data type, used to limit or allow the data stored in the column. For example, the column number is stored, the corresponding data type should be a numeric type.

Use data types help sort the data correctly, and plays an important role in optimizing disk usage. Therefore, you must set the correct data type and length of each column may create a table.

Common MySQL data types

In MySQL, common data types are as follows:

1) integer type

Including TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT, and floating-point type FLOAT DOUBLE, fixed point type DECIMAL.

2) date / time type

Including YEAR, TIME, DATE, DATETIME and TIMESTAMP.

3) Type String

Including CHAR, VARCHAR, BINARY, VARBINARY, BLOB, TEXT, ENUM SET, and the like.

4) binary type

包括 BIT、BINARY、VARBINARY、TINYBLOB、BLOB、MEDIUMBLOB 和 LONGBLOB。

Guess you like

Origin www.linuxidc.com/Linux/2019-09/160658.htm