【发布时间】: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