MySQL :: MySQL 8.0 Reference Manual :: 13.5 The JSON Data Type
相对于传统字符串字段存储json格式的好处:
1,自动校验json格式,无效的格式报错。
2,mysql会将json文本数据以内部格式存储,使用key或者index访问时不需要加载全文,访问更快。
json格式占用内存与LONGBLOB或LONGTEXT相似,但是也有一些额外的花销用来存储二进制编码后的数据(包括元数据、字典(查询json中的数据))。
json格式数据大小限制不能大于 max_allowed_packet 。
(
innoDB DYNAMIC Row Format
Fixed-length fields greater than or equal to 768 bytes are encoded as variable-length fields. For example, a CHAR(255)
column can exceed 768 bytes if the maximum byte length of the character set is greater than 3, as it is with utf8mb4
.
The DYNAMIC
row format supports index key prefixes up to 3072 bytes.
)
Prior to MySQL 8.0.13, a JSON
column cannot have a non-NULL
default value.
In MySQL 8.0.17 and later, the InnoDB storage engine supports multi-valued indexes on JSON arrays. See Multi-Valued Indexes.