我在Ubuntu Server 5.6
上使用MySQL 14.04
,并希望增加最大允许同时连接数(当前设置为默认151
)。
对此max_connections
中的/etc/mysql/my.cnf
设置负责。所以我将其设置为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
没效果。
答案 0 :(得分:1)
您必须增加操作系统上的打开文件限制,然后,您可以设置更高的max_connections值。
答案 1 :(得分:1)
[mysqld]
max_connections = 400
MAX_USER_CONNECTIONS = 300
你必须将max_connections属性添加到[mysqld]中。对我而言......