1. 查询
1.1. 方式一
show session variables like 'sort_buffer_size%';
show global variables like 'sort_buffer_size%';
1.2. 方式二
select @@session.sort_buffer_size as value;
select @@global.sort_buffer_size as value;
1.3. 方式三
select * from variables_info order by VARIABLE_SOURCE desc;
select * from session_variables;
select * from global_variables;
select * from persisted_variables;
select
sv.*, gv.VARIABLE_VALUE, pv.VARIABLE_VALUE, vi.*
from
variables_info vi
left join session_variables sv on vi.variable_name = sv.variable_name
left join global_variables gv on sv.variable_name = gv.variable_name
left join persisted_variables pv on gv.variable_name = pv.variable_name
order by vi.variable_source desc, pv.variable_name desc, gv.variable_name desc, sv.variable_name desc;
select * from variables_info order by VARIABLE_SOURCE desc; -- 所有变量
select * from persisted_variables;
- 4张表连表
2. 修改变量
2.1. 方式一
set session sort_buffer_size = 1024 * 1024;
set global sort_buffer_size = 1024 * 1024;
set persist sort_buffer_size = 1024 * 1024;
2.2. 方式二
set @@session.sort_buffer_size = 1024 * 1024;
set @@global.sort_buffer_size = 1024 * 1024;
set @@persist.sort_buffer_size = 1024 * 1024;
2.3. 方式三:修改配置文件(略)
- window修改my.ini, linux修改my.cnf
8. MariaDB
- 如果是
MariaDB
,改为连接数据库information_schema
,没有variables_info
、persisted_variables
,具体sql如下
select * from system_variables order by variable_scope desc;
select * from session_variables;
select * from global_variables;
select
sv.*, gv.VARIABLE_VALUE, vi.*
from
system_variables vi
left join session_variables sv on vi.variable_name = sv.variable_name
left join global_variables gv on sv.variable_name = gv.variable_name
order by vi.variable_scope, gv.variable_name desc, sv.variable_name desc;
9. 参考
新特性|MySQL 8.0 - 持久化参数
mysql set global 要不要重启_MySQL基础(七)