mysql详解11:数据类型

字符串类型
char 固定长度
varchar 不固定长度 可变数据类型
mediumtext
longtext
tinytext
text
整形类型
TINYINT [-128,127]
unsigned tinyint [0,255]
smallint [-32,32]
mediumint
int
bigint

decimal (9,2) 更精确 货币值
float 双精度 4b
doube 浮点型 8b

boolean 布尔类型
枚举和集合类型
ENUM('small','medium','large')
节约空间 但是修改麻烦
SET(...)

时间和日期类型
DATE
TIME
DATETIME 日期时间型
TIMESTAMP 时间戳 (up to 2038)
YEAR

Blob 类型
二进制长对象 存储大型二进制数据 如图像 视频 pdf word文件
TinyBlob
blob
文件存在数据库中 数据库的大小会迅速增加 弱化数据库备份功能 以及出现性能问题

json 类型 mysql 8以上版本 json类型有一组内置函数
{
“key":value
}
update products ’
set properties =JSON_OBJECT(
"dimensions",JSON_Array(1,2,3),
"weight",10,
'manufacturer',JSON_OBJECT('name',"sony"))'
where product_id =1;

SELECT product_id,JSON_EXTRACT(properties,'$.weight') weight
from products
where product_id =1;
方法二:

SELECT product_id,properties->'$.weight' weight
from products
where product_id =1;

SELECT product_id,properties->>'$.manufacturer.name'
from products
where product_id =1;

更新字段中某个属性:JSON_SET 更新现有属性或者添加新属性
update products
set properties =JSON_SET(
properties,
"$.weight",20,
"$.age",10
)

JSON_REMOVE()

原文地址:https://www.cnblogs.com/yxj808/p/15089993.html