MySQL 中的最大 JSON 列长度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40711101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 22:05:17  来源:igfitidea点击:

Max JSON column length in MySQL

mysqljson

提问by mark

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.

我可以在 MySQL 的 JSON 列中存储的最大字符数是多少?我在 MySQL 手册中没有看到这一点。

回答by Bill Karwin

Here's a demo of what @JorgeLondo?o is talking about.

这是@JorgeLondo?o 所谈论内容的演示。

Set the server's max allowed packet size:

设置服务器的最大允许数据包大小:

mysql> set global max_allowed_packet=1024*1024*1024;

Exit and open the mysql client again, this time setting the client max packet size to match:

退出并再次打开 mysql 客户端,这次设置客户端最大数据包大小匹配:

$ mysql --max-allowed-packet=$((1024*1024*1024*))

Create a test table with a JSON column and fill it with the longest JSON document you can:

创建一个带有 JSON 列的测试表,并用最长的 JSON 文档填充它:

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 |
+-----------+

This shows that I was able to create a single JSON document with 100 million elements, and MySQL stores this in approximately 800MB.

这表明我能够创建一个包含 1 亿个元素的 JSON 文档,MySQL 将其存储在大约 800MB 中。

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.

我没有尝试更长的文档。我假设它最大为 1 GB,这是您可以为 max_allowed_pa​​cket 设置的最大值。

回答by Jorge Londo?o

The size of JSON documents stored in JSON columns is limited to the value of the max_allowed_packetsystem variable. (While the server manipulates a JSON value internally in memory, it can be larger; the limit applies when the server stores it.)

存储在 JSON 列中的 JSON 文档的大小受限于max_allowed_packet系统变量的值。(虽然服务器在内存中内部操作 JSON 值,但它可以更大;当服务器存储它时,限制适用。)

Command-Line Format --max_allowed_packet=#
System Variable Name    max_allowed_packet
Variable Scope  Global, Session
Dynamic Variable    Yes
Permitted Values    Type    integer
Default 4194304
Min Value   1024
Max Value   1073741824