当前位置: 移动技术网 > IT编程>数据库>Mysql > MySQL数据类型

MySQL数据类型

2018年10月15日  | 移动技术网IT编程  | 我要评论

mysql之数据类型

mysql常见的数据类型有数值、日期和时间、字符串

数值

整数类型(精确值)

integer types (exact value) - integer, int, smallint, tinyint, mediumint, bigint

int
tinyint
bigint

不动点类型(精确值)-十进制,数字

fixed-point types (exact value) - decimal, numeric
decimal(5,2): 5代表精度,2代表刻度;表示该列总共可以存储5位数字,精确到小数点后2位;
存储范围: -999.99 ~ 999.99
numeric就是numeric
说明:精度是几,小数点+整数位不能超过前面的精度。
decimal(0) 默认是decimal(10,0)

浮点类型(近似值)-浮动

floating-point types (approximate value) - float, double
float 存储 4bytes
float(7,4)就会看到这样:-999.9999的显示。mysql进行舍入时存储的值,所以如果你插入999.00009成浮(7,4)柱,近似的结果是999.0001
if m and d are omitted, values are stored to the limits permitted by the hardware.
double 存储 8bytes

时间和日期

  • date:日期 'yyyy-mm-dd'. the supported range is '1000-01-01' to '9999-12-31'
  • datetime:日期时间组合 'yyyy-mm-dd hh:mm:ss' the supported range is '1000-01-01 00:00:00' to'9999-12-31 23:59:59'.
  • timestamp:时间戳 '1970-01-01 00:00:01.000000' utc to '2038-01-19 03:14:07.999999'       注意:不能等于'1970-01-01 00:00:00'会归零;
  • time:时间 '-838:59:59.000000' to '838:59:59.000000'      注意:'11:12' means '11:12:00', not '00:11:12' ; '1112' and 1112 as meaning '11:12:00;默认情况下,超出范围的值会被自动转换成接近的值,eg:'-850:00:00' and '850:00:00' are converted to '-838:59:59' and '838:59:59';无效的的时间值会被转换成'00:00:00'
  • year: range 1901 to 2155, or 0000    注意:year(4) and year(2)不同之处在于显示不同;eg:70 (1970 or 2070) or 69 (2069).

字符串

  • char:0 to 255 定长,存储时用空格补齐;读取时删掉后面的空格,pad_char_to_full_length sql模式开启
  • varchar:0 to 65,535 可变长度
  • blob:保存二进制的大型数据(字节串),没有字符集,eg:图片、音频视频等
  • text:保存非二进制字符串(字符串);有一个字符集
  • binary和varbinary:类似char和varchar;保存字节字符串,而不是字符字符串,这意味着它们没有字符集

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网