目录
Mysql5.7的新特性
Mysql的数值类型
日期和时间类型
字符串类型
数据类型的属性
注:以下图片来源为传智播客
Mysql5.7的新特性
我们知道mysql5.7新增了json的数据类型,下面列出json类型数据的简单操作
1.创建json类型字段
CREATE TABLE `test_table` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`content` json DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
2.Insert
INSERT into test_table VALUES(null,'{"name":"测试1","age":1}');
INSERT into test_table VALUES(null,'{"name":"测试2","age":10}');
3.select
SELECT json_extract(content,'$.name') as name ,json_extract(content,'$.age') as age from test_table
4.替换
update test_table set content=json_replace(content,'$.name',"测1") where json_extract(content,'$.age')=1
5.添加
update test_table set content=json_insert(content,'$.sex',"男") where json_extract(content,'$.age')=1
6.新增
update test_table set content=json_set(content,'$.sex1',"女") where json_extract(content,'$.age')=1
7.删除
update test_table set content=json_remove(content,'$.sex1') where json_extract(content,'$.age')=1
Mysql的数值类型
日期和时间类型
字符串类型
数据类型的属性