如何增加Ubuntu服务器上MySQL的max_connections值?

如何增加Ubuntu服务器上MySQL的max_connections值?

问题描述:

我在Ubuntu服务器14.04上使用MySQL 5.6,并且想要增加允许的最大同时连接数(当前设置为默认值151)。如何增加Ubuntu服务器上MySQL的max_connections值?

负责此操作的是/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  ¦ 
+--------------------------+-------+ 

为了避免错误的文件设置正确的configs的情况下,我在所有这些文件中设置的选项(有些人是不存在的,所以我创造了他们):

$ 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 

无影响。

您将不得不增加对您的操作系统的打开文件限制,并且之后可以将更高的max_connections值。

+0

刚刚完成('ulimit -n 4096')并重新启动MySQL。没有效果。 – automatix

[mysqld] 

MAX_CONNECTIONS = 400个

MAX_USER_CONNECTIONS = 300

你必须max_connections属性添加为下面的[mysqld]。对我来说它的工作..