问题描述
我可以在MySQL的JSON列中存储的最大字符数是多少?我没有在MySQL手册中看到这一点.
What's the max number of characters I can store in a JSON column in MySQL? I don't see this mentioned in the MySQL manual.
推荐答案
这里是@JorgeLondoño谈论的演示.
Here's a demo of what @JorgeLondoño is talking about.
设置服务器允许的最大数据包大小:
Set the server's max allowed packet size:
mysql> set global max_allowed_packet=1024*1024*1024;
退出并再次打开mysql客户端,这次将客户端的最大数据包大小设置为匹配:
Exit and open the mysql client again, this time setting the client max packet size to match:
$ mysql --max-allowed-packet=$((1024*1024*1024*))
使用JSON列创建测试表,并用最长的JSON文档填充它:
Create a test table with a JSON column and fill it with the longest JSON document you can:
mysql> create table test.jtest ( j json );
mysql> insert into test.jtest
set j = concat('[', repeat('"word",', 100000000), '"word"]');
Query OK, 1 row affected (1 min 49.67 sec)
mysql> select length(j) from test.jtest;
+-----------+
| length(j) |
+-----------+
| 800000008 |
+-----------+
这表明我能够创建一个包含1亿个元素的JSON文档,而MySQL将其存储在大约800MB中.
This shows that I was able to create a single JSON document with 100 million elements, and MySQL stores this in approximately 800MB.
我没有尝试更长的文档.我假设它最大为1 GB,这是您可以为max_allowed_packet设置的最大值.
I didn't try a longer document. I assume it maxes out at 1 GB, which is the largest value you can set for max_allowed_packet.
这篇关于MySQL中的最大JSON列长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!