按照官网的解释:
Each session that must perform a sort allocates a buffer of this size. sort_buffer_size is not specific to any storage engine and applies in a general manner for optimization. At minimum the sort_buffer_size value must be large enough to accommodate fifteen tuples in the sort buffer. Also, increasing the value of max_sort_length may require increasing the value of sort_buffer_size. For more information, see Section 8.2.1.14, “ORDER BY Optimization”

sort_buffer_size 是一个connection级参数,在每个connection需要buffer的时候,一次性分配的内存。
sort_buffer_size 并不是越大越好,过大的设置+高并发可能会耗尽系统内存资源。

1.查看sort_buffer_size默认值,默认值为256K

mysql> show variables like 'sort_buffer_size';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| sort_buffer_size | 262144 |
+------------------+--------+
1 row in set (0.00 sec)

2.设置global级别的sort_buffer_size值,设置sort_buffer_size=1M

mysql> SET GLOBAL sort_buffer_size = 1024*1024;
Query OK, 0 rows affected (0.00 sec)

3.设置session级别的sort_buffer_size值,设置sort_buffer_size=2M

mysql> SET session sort_buffer_size = 2*1024*1024;
Query OK, 0 rows affected (0.00 sec) mysql> show variables like 'sort_buffer_size';
+------------------+---------+
| Variable_name | Value |
+------------------+---------+
| sort_buffer_size | 2097152 |
+------------------+---------+
1 row in set (0.00 sec)

4.设置永久生效,需要修改/etc/my.cnf文件,重启Mysql后生效

[mysqld]
# 固定Mysql sort_buffer_size参数
sort_buffer_size=1M
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=D:\mysql-8.0.25-winx64 # 切记此处一定要用双斜杠\\,单斜杠我这里会出错
# 设置mysql数据库的数据的存放目录
datadir=D:\mysql-8.0.25-winx64\\data # data目录之后初始化会自动创建
# 允许最大连接数
max_connections=200
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10
# 服务端使用的字符集默认为UTF8
character-set-server=utf8mb4
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
default_authentication_plugin=mysql_native_password
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8mb4
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8mb4

设置Mysql sort_buffer_size参数的更多相关文章

  1. 设置Mysql的连接超时参数

     在Mysql的默认设置中,如果一个数据库连接超过8小时没有使用(闲置8小时,即   28800s),mysql server将主动断开这条连接,后续在该连接上进行的查询操作都将失败,将   出现:e ...

  2. 1201MySQL配置文件mysql.ini参数详解

    转自http://www.cnblogs.com/feichexia/archive/2012/11/27/mysqlconf.html my.ini(Linux系统下是my.cnf),当mysql服 ...

  3. (转)MySQL配置文件mysql.ini参数详解、MySQL性能优化

    本文转自:http://www.cr173.com/html/18331_1.html my.ini(Linux系统下是my.cnf),当mysql服务器启动时它会读取这个文件,设置相关的运行环境参数 ...

  4. MySQL配置文件mysql.ini参数详解、MySQL性能优化

    my.ini(Linux系统下是my.cnf),当mysql服务器启动时它会读取这个文件,设置相关的运行环境参数. my.ini分为两块:Client Section和Server Section.  ...

  5. MySQL配置文件mysql.ini参数详解

    my.ini(Linux系统下是my.cnf),当mysql服务器启动时它会读取这个文件,设置相关的运行环境参数. my.ini分为两块:Client Section和Server Section. ...

  6. mysql配置文件参数详解

    (一) [client]port = 3306socket = /tmp/mysql.sock [mysqld]port = 3306socket = /tmp/mysql.sock basedir ...

  7. mysql服务器参数

    mysql服务器参数: 配置是从上往下读取,同一个参数项,后边的配置项会覆盖前边的配置项 mysql获取配置信息路径: 命令行参数    mysqld_safe  --datadir=/data/sq ...

  8. mysql内存参数整理和条调优以及内存统计

    date:20140530auth:Jin 参考:http://dev.mysql.com/doc/refman/5.5/en/server-status-variables.html#http:// ...

  9. 第四课(2)——mysql配置参数讲解

    *****************general***************** user 启动mysql domain的用户 port 数据库端口号 socket 数据库socket文件的路径 p ...

  10. mysql 常见参数

    my.cnf[client] 对mysql的所有客端都生效的[mysql] 只对mysql这个命令有效了[mysqd][mysqld_multi] 多实例启动[mysqld_safe][mysqldN ...

随机推荐

  1. Day11-数组的使用

    数组的使用 一.数组的使用 package com.array; public class ArrayDemo03 { public static void main(String[] args) { ...

  2. Java 获取【.jar】文件里的资源文件

    获取jar文件里的图片等文件时,会发现使用相对路径不行了. 因为打包后的jar文件,在获取路径时稍有不同. 下面是获取jar文件中图片的例子: 1 Resource[] resources = new ...

  3. 后台传回来的Map类型的数据在前台中的JS代码中使用

    Map<String, String> projectTypeCodeMap = SysCodeUtils.getSysCodeMap(request, CommonFields.XT_P ...

  4. chatGpt启示

    在应用软件领域实现自动化编程,我现在确实不怀疑了,只是还要等几年的问题.所以我的建议是:如果还想撸代码,可以往基础软件方向走,或者直接去大公司做 AI 工具:不想搞软件了,就去多了解业务吧.早做准备早 ...

  5. PTA1003 我要通过! (20 分)

    PTA1003 我要通过! (20 分) "答案正确"是自动判题系统给出的最令人欢喜的回复.本题属于 PAT 的"答案正确"大派送 -- 只要读入的字符串满足下 ...

  6. 终端命令mix

    Jdk(1.7) java -version Maven是否安装 mvn -v MySQL(5.7) mysql -uroot -p /Users/zhanzhanyunjiu/Documents/a ...

  7. Linux目录结构说明与基本操作

    Linux系统目录如下: 详细说明如下: Linux系统文件与目录的基本操作: 一.显示文件内容命令--cat.more.less.head.tail. 1.cat命令 该命令的主要功能是用来显示文件 ...

  8. Vue系列---【.npmrc文件设置私服地址】

    一..npmrc 配置文件的优先级 电脑中有多个 .npmrc 文件,在我们安装包的时候,npm按照如下顺序读取这些配置文件 项目配置文件: /project/.npmrc 用户配置文件:~/.npm ...

  9. 使用idea从零编写SpringCloud项目-Ribbo

    git:https://github.com/bmdcheng/product_server git:https://github.com/bmdcheng/order_server 1.需要创建两个 ...

  10. Charles4.5.1抓取HTTPS请求

    Charles下载以后发现 抓取http请求是成功的: 抓取https请求是失败的: 按照失败提示设置即可: 1.点击 Help -> SSL Proxying -> install ch ...