MySQL Variables max_sort_length 数据库 参数变量解释及正确配置使用
本站中文解释
1、max_sort_length变量:
max_sort_length变量用于控制MySQL在排序过程中最大的字符串长度,单位是字节。MySQL将对能够被完全加载进内存中的字符串进行排序,如果字符串太长则无法加载进内存,此时如果字符串无法比较则会返回异常。
2、为何设置max_sort_length参数:
这个参数可以避免MySQL在排序时出现溢出以及异常,确保排序过程的正常进行,设置max_sort_length参数的值可以更好的发挥MySQL的性能。
3、如何设置max_sort_length参数:
MySQL中可以通过命令行或者在配置文件中设置max_sort_length参数:
(1)使用命令行设置:
在MySQL中可以通过以下命令设置max_sort_length参数:
SET GLOBAL max_sort_length = ;
其中代表你要设置的值,这个参数的最大值可以设置为8388607,设置这个参数后,需要调用flush tables语句才能让设置生效。
(2)在配置文件中设置:
在配置文件my.cnf中也可以设置max_sort_length参数,也就是将下面这一行添加到配置文件的[mysqld]节中:
max_sort_length=
修改完毕后,重启MySQL即可生效。
官方英文解释
max_sort_length
Command-Line Format | --max-sort-length=# |
---|---|
System Variable | max_sort_length |
Scope | Global, Session |
Dynamic | Yes |
Type | Integer |
Default Value | 1024 |
Minimum Value | 4 |
Maximum Value | 8388608 |
Unit | bytes |
The number of bytes to use when sorting data values. The
server uses only the first
max_sort_length
bytes of each
value and ignores the rest. Consequently, values that differ
only after the first
max_sort_length
bytes compare
as equal for GROUP BY
, ORDER
, and
BYDISTINCT
operations.
Increasing the value of
max_sort_length
may require
increasing the value of
sort_buffer_size
as well. For
details, see Section 8.2.1.14, “ORDER BY Optimization”