数据类型
类型名 | MySQL类型 | python类型 | 描述 | 子节占据 | 表示形式 | 范围 | 选择 |
---|
SmallInteger | smallint | int | 取值范围较小,一般为16位 | | | | |
数字 | - | - | - | - | - | - | - |
Integer | int | int | 普通整数,一般32位 | | | | |
BigInteger | bigint | int/long | 不限精度的整数 | | | | |
Float | float | float | 浮点数 | | | | |
Numeric | decimal | decimal.Decimal | 定点数 | | | | |
字符串 | - | - | - | - | - | - | - |
String | varchar | str | 变长字符串 | | | | |
Text | tinytext | str | 变长字符串,64K,2 16 − 1 2^{16}-12 16 −1=65535bytes | | | | |
Text(65536) | mediumtext | str | 变长字符串,max16M,2 24 − 1 2^{24}-12 24 −1=16777215bytes | | | | |
Text(16777216) | longtext | str | 变长字符串,max32M,2 32 − 1 2^{32}-12 32 −1=4294967295bytes | | | | |
Unicode | varchar | unicode | 变长字符串 | | | | |
UnicodeText | text | unicode | 变长字符串,64K | | | | |
二进制 | - | - | - | - | - | - | - |
LargeBinary | blob | str | 二进制文件,64K | | | | |
LargeBinary(65536) | mediumblob | str | 二进制,max16M | | | | |
LargeBinary(16777216) | longblob | str | 二进制,max32M | | | | |
PickleType | blob | 任何python对象 | 自动使用Pickle序列化,只有blob | | | | |
Boolean | tinyint | bool | 布尔值 | | | | |
日期 | - | - | - | - | - | - | - |
Date | date | datetime.date | 日期 | | | | |
Time | time | date.time | 时间 | | | | |
DateTime | datetime | datetime.datetime | 日期和时间 | 8字节 | yyyy-mm-dd hh:mm:ss | '1000-01-01 00:00:00.000000' to '9999-12-31 23:59:59.999999' | 服务器时区不一样 |
Interval | datetime | datetime.timedelta | 时间间隔 | | | | |
| timestamp | | 时间挫 | 4字节 | yyyy-mm-dd hh:mm:ss | '1970-01-01 00:00:01.000000' to '2038-01-19 03:14:07.999999' | 自动插入时间或者自动更新时间 |
- | - | - | - | - | - | - | - |
Enum | enum | str | 一组字符串 | | | | |
备注
如果存进去的是NULL,
timestamp会自动储存当前时间
datetime会储存 NULL
下面都是 MySQL 允许的形式,MySQL 会自动处理
2016-10-01 20:48:59
2016#10#01 20/48/59
20161001204859