动态修改MYSQL配置参数

mysql数据库也像ORACLE数据库一样,可以动态的修改参数,可以修改会话级变量只对当前会话产生影响;也可以修改全局变量,对所有新连接的会话都产生影响。

修改会话级变量

用show variables 命令查看当前参数的值,like 'pattern'用于模式匹配,查找指定的参数

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

用set SESSION命令设置会话级变量的新值

mysql> set SESSION sort_buffer_size=7000000;
Query OK, 0 rows affected (0.00 sec)

--修改会话级变量对当前会话来说立刻生效
mysql> show variables like '%sort_buffer_size%';        
+---------------------------+------------+
| Variable_name             | Value      |
+---------------------------+------------+
| sort_buffer_size          | 7000000    |
+---------------------------+------------+
1 rows in set (0.00 sec)

mysql> exit
Bye
退出重新连接后,此参数恢复原值
[root@devdbc_stb root]# mysql
Welcome to the MySQL monitor.  Commands end with ; or /g.
Your MySQL connection id is 40 to server version: 5.0.37-log

Type 'help;' or '/h' for help. Type '/c' to clear the buffer.

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

修改全局变量
[root@devdbc_stb root]# mysql
Welcome to the MySQL monitor.  Commands end with ; or /g.
Your MySQL connection id is 40 to server version: 5.0.37-log

Type 'help;' or '/h' for help. Type '/c' to clear the buffer.

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

用set GLOBAL 命令设置全局变量

mysql> set GLOBAL sort_buffer_size = 7000000;
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like '%sort_buffer_size%';         
+---------------------------+------------+
| Variable_name             | Value      |
+---------------------------+------------+
| sort_buffer_size          | 6291448    |
+---------------------------+------------+
1 rows in set (0.00 sec)
当前此参数的值并不发生变化,先退出,然后重新连进去
mysql> exit
Bye
[root@devdbc_stb root]# mysql
Welcome to the MySQL monitor.  Commands end with ; or /g.
Your MySQL connection id is 41 to server version: 5.0.37-log

Type 'help;' or '/h' for help. Type '/c' to clear the buffer.

mysql> show variables like '%sort_buffer_size%';
+---------------------------+------------+
| Variable_name             | Value      |
+---------------------------+------------+
| sort_buffer_size          | 7000000    |
+---------------------------+------------+
1 rows in set (0.00 sec)
新的参数值生效

 

 新的参数值生效 这些参数的改变在重启MYSQL服务的时候,都将失效复原,如果想要重启的时候也载入,则需要修改配置文件

 

原文地址:http://blog.chinaunix.net/uid-26263325-id-3027255.html

posted on   咚..咚  阅读(236)  评论(0编辑  收藏  举报

编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示