MysqlJSON
Summary: Author: 张亚飞 | Read Time: 1 minute read | Published: 2016-05-13
Filed under
—
Categories:
Linux
—
Tags:
Note,
建表
CREATE TABLE `test_user`(`id` INT PRIMARY KEY AUTO_INCREMENT, `name` VARCHAR(50) NOT NULL, `info` JSON);
插入数据:
mysql> INSERT INTO test_user(`name`, `info`) VALUES('xiaoming','{"sex": 1, "age": 18, "nick_name": "小萌"}');
mysql> INSERT INTO test_user(`name`, `info`) VALUES('xiaohua', JSON_OBJECT("sex", 0, "age", 17));
mysql> INSERT INTO test_user(`name`, `info`) VALUES('xiaozhang', JSON_OBJECT("sex", 1, "age", 19, "tag", JSON_ARRAY(3,5,90)));
mysql> select * from test_user;
查询
mysql> select name, info->'$.nick_name', info->'$.sex', info->'$.tag[0]' from test_user;
Comments