mysql 数据类型
2016-03-30 23:49
411 查看
类型
整型
tinyint 0 -- 255 -128---127
smallint
mediumint
int
bigint
小数型
float
decimal
字符串类型
varchar
char
text
日期型
date
datetime
time
year
Tinyint 创建之后 默认是有符号的 -128-127的
整形可选属性
M:宽度 zerofill填充0才有意义
Unsigned 无符号类型
Zerofill 用0填充 默认无符号
浮点型
Float(M,D) 浮点型
Decimal(M,D) 9999.99 --- -9999.99 定点型 更精确
固定占 4个字节 要么是8个字节
M 精度 不包含小数点的总长度
D 标度 小数点后面的长度
字符型
Char 定长 (M) 代表可容纳的字符数
Varchar 变长 (M) 代表可容纳的字符数
定长 如果小于M个字符 实占M个字符
变长 如果小于M 那就存N个字节 N<=M 实占N个字节加上1~2个字节 2个字节标志 可以写到 65535 (以 ascii 字符可以65535 如果gbk utf8的话22000左右,如果是5.0.3以下版本 只能存255个字节)
Char 定长类型 如果少于长度 用空格补齐 如果尾部是空格 那么就丢失了
Text 能存很大的数据 但是搜索很慢 而且 text无法加默认值
日期和时间
年 year 1个字节表示 1901 -2155 还少了一个字节 预留的 000000年
年月日 date
09:00:00 time
年月日 时分秒 datetime
Year 如果输入2位的话 ‘00-69’ 那么表示 2000-2069
如果2位是‘70-99’ 表示 1970--1999
Date 类型 1908-01-23 1000-01-01 ~~~ 9999-12-31
Time 时间类型 hh:mm:ss -838:59:59 ~~~ 838:59:59 还可以用来表示2个事件的时间间隔
Datetime 日期时间类型 1000-01-01 00:00:00 ~~~ 9999-12-31 23:59:59
时间戳
1970-01-01 00:00:00 到当前秒数
一般发布商品 用时间戳 不用datetime 因为datetime虽然直观但是计算不便
建表语句
Create table 表名 (
列1 列属性 默认值,
列2 列属性 默认值,
列3 列属性 默认值
)
Engine = 存储引擎
Charrset = 编码
create table php (
id int primary key auto_increment,
name char(3) not null default '',
age tinyint unsigned not null default 0,
email varchar(30) not null default '',
tel char(11) not null default '',
salary decimal(7,2) not null default '1800.68',
riqi date not null default '2012-03-01'
)charset utf8;
转载地址 http://blog.csdn.net/ebw123/article/details/8043136
整型
tinyint 0 -- 255 -128---127
smallint
mediumint
int
bigint
小数型
float
decimal
字符串类型
varchar
char
text
日期型
date
datetime
time
year
类型 | 字节 | 占几位 | 无符号 | 有符号 |
Tinyint | 1 | 8 | 0->2^8-1 255 3位 | -2^7->2^7-1 -128--127 |
Smallint | 2 | 16 | 0->2^16-1 65535 5位 | -2^15->2^15-1 -32768 -32767 |
Mediumint | 3 | 24 | 0->2^24-1 16777215 8位 | -2^23->2^23-1 -8388608-8388607 |
Int | 4 | 32 | 0->232-1 4294967295 十位 | -2^31->2^31 -1 ~2147483648 十忆 |
Bigint | 8 | 64 | 184467440 ~20位 | 9223372036 ~ 19位 |
整形可选属性
M:宽度 zerofill填充0才有意义
Unsigned 无符号类型
Zerofill 用0填充 默认无符号
浮点型
Float(M,D) 浮点型
Decimal(M,D) 9999.99 --- -9999.99 定点型 更精确
固定占 4个字节 要么是8个字节
M 精度 不包含小数点的总长度
D 标度 小数点后面的长度
字符型
Char 定长 (M) 代表可容纳的字符数
Varchar 变长 (M) 代表可容纳的字符数
定长 如果小于M个字符 实占M个字符
变长 如果小于M 那就存N个字节 N<=M 实占N个字节加上1~2个字节 2个字节标志 可以写到 65535 (以 ascii 字符可以65535 如果gbk utf8的话22000左右,如果是5.0.3以下版本 只能存255个字节)
Char 定长类型 如果少于长度 用空格补齐 如果尾部是空格 那么就丢失了
Text 能存很大的数据 但是搜索很慢 而且 text无法加默认值
日期和时间
年 year 1个字节表示 1901 -2155 还少了一个字节 预留的 000000年
年月日 date
09:00:00 time
年月日 时分秒 datetime
Year 如果输入2位的话 ‘00-69’ 那么表示 2000-2069
如果2位是‘70-99’ 表示 1970--1999
Date 类型 1908-01-23 1000-01-01 ~~~ 9999-12-31
Time 时间类型 hh:mm:ss -838:59:59 ~~~ 838:59:59 还可以用来表示2个事件的时间间隔
Datetime 日期时间类型 1000-01-01 00:00:00 ~~~ 9999-12-31 23:59:59
时间戳
1970-01-01 00:00:00 到当前秒数
一般发布商品 用时间戳 不用datetime 因为datetime虽然直观但是计算不便
建表语句
Create table 表名 (
列1 列属性 默认值,
列2 列属性 默认值,
列3 列属性 默认值
)
Engine = 存储引擎
Charrset = 编码
create table php (
id int primary key auto_increment,
name char(3) not null default '',
age tinyint unsigned not null default 0,
email varchar(30) not null default '',
tel char(11) not null default '',
salary decimal(7,2) not null default '1800.68',
riqi date not null default '2012-03-01'
)charset utf8;
转载地址 http://blog.csdn.net/ebw123/article/details/8043136
相关文章推荐
- 客户端工具用多了 有弊端;mysql一些知识
- MYSQL的常用命令和增删改查语句和数据类型
- 配置解压版mysql5.7方法
- 关于mysql的update、delete、和insert into能否使用别名问题
- mysql建索引杂谈
- mysql更改表结构:添加、删除、修改字段、调整字段顺序
- mysql优化经验
- 常用的三种修改mysql最大连接数的方法
- Mysql 关键字做表名,出现插不进去数据,解决方法
- MySQL解压版安装配置详解
- MYSQL中group_concat有长度限制!默认1024
- 还是mysql的问题
- Mac下配置mysql环境变量的另一种方式
- mysql 安装
- mysql 时间戳格式化函数from_unixtime使用说明
- ubuntu 15.04 通过3306端口远程连接mysql
- Mysql学习笔记之常用数据类型
- 《MySQL必知必会学习笔记》:子查询
- 修改mysql用户密码
- MySQL解压缩版配置安装方法