my.cnf配置修改重启后不生效,原因分析解决,max_connections配置修改重启后不生效

先说结论:max_connections配置不生效,被open_files_limit这个参数影响了,这个open_files_limit参数过大失效,恢复成了默认值1024,max_connections默认取你设置的值跟open_files_limit-810两者的最小值。

原因:
mysqld在启动的时候,根据上述三种算法对该变量进行调整,并取三种算法中的最大值。也就是说最终确定的open_files_limit 可能比你设定的大,也可能小。
下面我们再瞅一眼源码(mysqld.cc):

 /**
   Adjust @c open_files_limit.
   Computation is  based on:
   - @c max_connections,
   - @c table_cache_size,
   - the platform max open file limit.
 */
 void adjust_open_files_limit(ulong *requested_open_files)
 {
   ulong limit_1;
   ulong limit_2;
   ulong limit_3;
   ulong request_open_files;
   ulong effective_open_files;
 
   /* MyISAM requires two file handles per table. */
   limit_1= 10 + max_connections + table_cache_size * 2;
 
   /*
     We are trying to allocate no less than max_connections*5 file
     handles (i.e. we are trying to set the limit so that they will
     be available).
   */
   limit_2= max_connections * 5;
 /* Try to allocate no less than 5000 by default. */
   limit_3= open_files_limit ? open_files_limit : 5000;
 
   request_open_files= max<ulong>(max<ulong>(limit_1, limit_2), limit_3);
 
   /* Notice: my_set_max_open_files() may return more than requested. */
   effective_open_files= my_set_max_open_files(request_open_files);
 //最终确定的值可能会比你设定的值大,也可能小。 如果小的话下面这段代码是打出两个警告信息。大的话当然没关系啦。
   if (effective_open_files < request_open_files)
   {
     if (open_files_limit == 0)
     {
       sql_print_warning("Changed limits: max_open_files: %lu (requested %lu)",
                         effective_open_files, request_open_files);
     }
     else
     {
       sql_print_warning("Could not increase number of max_open_files to "
                         "more than %lu (request: %lu)",
                         effective_open_files, request_open_files);
     }
   }
 
   open_files_limit= effective_open_files;
   if (requested_open_files)
     *requested_open_files= min<ulong>(effective_open_files, request_open_files);
 }

这段源码很容易看懂,注释很详细,官方文档的解释与源码也很相符。按照三种算法,算出三个limit值,最后取其中最大的一个去设定这个变量。通过源码我们也可以看到open_files_limit,table_open_cache,max_connections这几个参数是密切相关的。

也就是说参数的设置规则来自4个方面:

10 + max_connections + (table_open_cache * 2)
max_connections * 5
操作系统设置的open files
参数open_files_limit的设置,默认值为5000
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值