mysql8存取json

1、建表

CREATE TABLE `test` (
`id` bigint NOT NULL,
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`msg` json NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;

2、插入语句

INSERT INTO `test`
VALUES
( 3, 'feng', '{"email": "abc@example.com", "phone": "+11800000000", "address": {"pin": "560103", "city": "Bangalore", "line1": "abc", "line2": "xyz street"}, "location": "IN"}' );

3、查询

select id,name, msg -> '$.phone'  ph, msg -> '$.address.city'  city  from test;

posted @ 2023-04-24 14:06  大日很忧伤  阅读(79)  评论(0编辑  收藏  举报