温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

不重启mysql情况修改参数变量

发布时间:2020-08-06 19:58:34 来源:ITPUB博客 阅读:220 作者:不一样的天空w 栏目:MySQL数据库

https://www.cnblogs.com/huidaoli/p/3232265.html

地球人都知道,更新mysql配置my.cnf需要重启mysql才能生效,但是有些时候mysql在线上,不一定允许你重启,这时候应该怎么办呢?

看一个例子:

1
2
3
4
5
6
7
8
9
10
mysql> show variables like 'log_slave_updates';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| log_slave_updates | OFF   |
+-------------------+-------+
1 row in set (0.00 sec)
 
mysql> set global log_slave_updates=1;
ERROR 1238 (HY000): Variable 'log_slave_updates' is a read only variable

看到了吧?报错了!

后来查了一下资料,发现有一个叫gdb的东西,感觉相当牛X,可以实现在线更改mysql参数,请看例子:

1
2
3
4
5
6
7
8
mysql> system gdb -p $(pidof mysqld) -ex "set opt_log_slave_updates=1" -batch
mysql> show variables like 'log_slave_updates';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| log_slave_updates | ON    |
+-------------------+-------+
1 row in set (0.00 sec)

但是在一些可重复的参数,不能直接用set更改,那这时候又要怎么办呢?老外给了一个解决方案:

1
2
3
4
5
6
7
8
9
10
mysql> show slave status \G
...
     Replicate_Do_DB: test
...
mysql> system gdb -p $(pidof mysqld)
          -ex 'call rpl_filter->add_do_db(strdup("hehehe"))' -batch
mysql> show slave status \G
...
      Replicate_Do_DB: test,hehehe
...

=========================================================================

   mysql很多参数都需要重启才能生效,有时候条件不允许,可以使用gdb作为最后的手段

先看看修改之前

mysql> show global variables like '%connection%';
+--------------------------+-------------------+
| Variable_name            | Value             |
+--------------------------+-------------------+
| character_set_connection | latin1            |
| collation_connection     | latin1_swedish_ci |
| max_connections          | 151               |
| max_user_connections     | 0                 |
+--------------------------+-------------------+
4 rows in set (0.01 sec)


使用gdb来修改


[root@asm ~]# gdb -p $(pidof mysqld) -ex "set max_connections=1500" -batch

 其他的参数可以相应的修改


再查看当前的配置

mysql> show global variables like '%connection%';
+--------------------------+-------------------+
| Variable_name            | Value             |
+--------------------------+-------------------+
| character_set_connection | latin1            |
| collation_connection     | latin1_swedish_ci |
| max_connections          | 1500              |
| max_user_connections     | 0                 |
+--------------------------+-------------------+
4 rows in set (0.00 sec)

 可以看出修改成功了,不过使用gdb有风险,特别是生产环境,有可能导致进程down掉,仅作为最后手段使用.

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI