mysql数据类型
Posted 你很棒
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql数据类型相关的知识,希望对你有一定的参考价值。
数据类型基本介绍
数值类型
整形类型:tinyint,int,bigint 浮点类型:float,double
字符串类型
char系列:char varchar text系列:text blob系列:blob 枚举类型:ENUM 集合类型:SET
时间日期型
date time datetime timestamp year
tinyint和int整形测试
mysql> create table test1(tinyint_test tinyint,int_test int); Query OK, 0 rows affected (0.03 sec)
mysql> desc test1; +--------------+------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------+------------+------+-----+---------+-------+ | tinyint_test | tinyint(4) | YES | | NULL | | | int_test | int(11) | YES | | NULL | | +--------------+------------+------+-----+---------+-------+ 2 rows in set (0.05 sec)
mysql> insert into test1 values(111,111); Query OK, 1 row affected (0.01 sec)
mysql> select * from test1; +--------------+----------+ | tinyint_test | int_test | +--------------+----------+ | 111 | 111 | +--------------+----------+ 1 row in set (0.00 sec)
mysql> insert into test1(tinyint_test) values(128); ERROR 1264 (22003): Out of range value for column ‘tinyint_test‘ at row 1
mysql> insert into test1(int_test) values(mysql> insert into test1(int_test) values(2147483647); Query OK, 1 row affected (0.01 sec)
mysql> insert into test1(int_test) values(2147483648); ERROR 1264 (22003): Out of range value for column ‘int_test‘ at row 1
整形宽度测试
mysql> create table test2(id1 int,id2 int(8));
mysql> desc test2; +-------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+---------+------+-----+---------+-------+ | id1 | int(11) | YES | | NULL | | | id2 | int(8) | YES | | NULL | | +-------+---------+------+-----+---------+-------+
mysql> insert into test2 values(1,1);
mysql> select * from test2; +------+------+ | id1 | id2 | +------+------+ | 1 | 1 | +------+------+
mysql> create table test3(id1 int zerofill,id2 int(8) zerofill);
mysql> insert into test3 values(123456789,123456789);
总结:整形宽度总是做填充使用,没有实际意义mysql> select * from test3; +------------+-----------+ | id1 | id2 | +------------+-----------+ | 0123456789 | 123456789 | +------------+-----------+
浮点数类型测试-float
mysql> create table test1(float_test float(5,2)); //一共5位,也就是整数+小数一共5位,同时小数最多2位
mysql> insert into test1 values(1000.123); ERROR 1264 (22003): Out of range value for column ‘float_test‘ at row 1
mysql> insert into test1 values(999.123);
mysql> select * from test1; +------------+ | float_test | +------------+ | 999.12 | +------------+
以上是关于mysql数据类型的主要内容,如果未能解决你的问题,请参考以下文章
对“xxx”类型的已垃圾回收委托进行了回调。这可能会导致应用程序崩溃损坏和数据丢失。向非托管代码传递委托时,托管应用程序必须让这些委托保持活动状态,直到确信不会再次调用它们。 错误解决一例。(代码片段
连接MySQL出现错误:ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)(代码片段