原文:https://www.cnblogs.com/sensenh/p/15397864.html
mysql5.7以上支持json的操作,以及增加了json存儲類型
一般數據庫存儲json類型的數據會用json類型或者text類型
表數據
使用 字段->’$.json屬性’進行查詢條件
select * from log where data->'$.id' = 142;
或
select data->'$.id' id,data->'$.name' name from log where data->'$.id' = 142;
更多方案:https://www.jb51.net/article/230855.htm
。表數據
select * from product where suit like '%"10001"%'; #like方式不能使用索引,性能不佳,且准確性不足 select * from product where suit LOCATE('"10001"', 'suit') > 0; # LOCATE方式和like存在相同問題 select * from product where suit != '' and json_contains('suit'->'$.hotel', '"10001"'); #以MySQL內置json函數查找,需要MySQL5.7以上版本才能支持,准確性較高,不能使用全文索引 select * from product where MATCH(suit) AGAINST('+"10001"' IN BOOLEAN MODE); #可使用全文索引,MySQL關鍵字默認限制最少4個字符,可在mysql.ini中修改 ft_min_word_len=2,重啟后生效