【问题标题】:How to increase the max_connections value for MySQL on Ubuntu Server?如何在 Ubuntu Server 上增加 MySQL 的 max_connections 值?
【发布时间】:2017-08-15 08:09:48
【问题描述】:

我在 Ubuntu Server 14.04 上使用 MySQL 5.6,并希望增加允许的最大同时连接数(当前设置为默认 151)。

对此负责的是/etc/mysql/my.cnf 中的设置max_connections。所以我将其设置为200 并重新启动了 MySQL 服务器。现在,它的值是200

$ cat /etc/mysql/my.cnf | grep "connections"
max_connections        = 200
$ /etc/init.d/mysql restart
 * Stopping MySQL database server mysqld                                                                                             [ OK ] 
 * Starting MySQL database server mysqld                                                                                             [ OK ] 
 * Checking for tables which need an upgrade, are corrupt or were 
not closed cleanly.

但什么都没有改变:

SHOW VARIABLES LIKE "max_connections";
+-----------------+-------+
¦ Variable_name   ¦ Value ¦
+-----------------+-------+
¦ max_connections ¦ 151   ¦
+-----------------+-------+

如何让max_connections 的自定义配置生效?


$ ulimit -a | grep "open"
open files                      (-n) 1024
$ ulimit -n 4096
$ ulimit -a | grep "open"
open files                      (-n) 4096

添加到/etc/security/limits.conf

* soft nofile 1024000
* hard nofile 1024000
* soft nproc 10240
* hard nproc 10240
root soft nproc unlimited

添加到/etc/mysql/my.cnf

[mysqld_safe]
open_files_limit = 1024000
[mysqld]
open_files_limit = 1024000

但是好像被忽略了:

SHOW STATUS LIKE 'open%';
+--------------------------+-------+
¦ Variable_name            ¦ Value ¦
+--------------------------+-------+
¦ Open_files               ¦ 52    ¦
+--------------------------+-------+
¦ Open_streams             ¦ 0     ¦
+--------------------------+-------+
¦ Open_table_definitions   ¦ 434   ¦
+--------------------------+-------+
¦ Open_tables              ¦ 417   ¦
+--------------------------+-------+
¦ Opened_files             ¦ 847   ¦
+--------------------------+-------+
¦ Opened_table_definitions ¦ 0     ¦
+--------------------------+-------+
¦ Opened_tables            ¦ 0     ¦
+--------------------------+-------+

为了避免在错误文件中设置正确配置的情况,我在所有这些文件中设置了选项(其中一些文件不存在,所以我创建了它们):

$ mysqld --help --verbose | grep -B 1 cnf
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf

没有效果。

【问题讨论】:

    标签: configuration ubuntu-14.04 configuration-files mysql-5.6 my.cnf


    【解决方案1】:
    [mysqld]
    

    max_connections = 400

    max_user_connections=300

    您必须将 max_connections 属性添加到 [mysqld] 中,如下所示。对我来说它的工作..

    【讨论】:

      【解决方案2】:

      您将不得不增加操作系统的打开文件限制,然后,您可以设置更高的 max_connections 值。

      【讨论】:

      • 刚刚完成 (ulimit -n 4096) 并重新启动 MySQL。没有效果。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-14
      • 2021-06-08
      • 2015-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多