知道为什么我无法在 MySQL 中更改 max_connections 吗?堆栈是:Ubuntu 14.04 和 MySQL 5.7.15
mysql> select @@global.open_files_limit;
+---------------------------+
| @@global.open_files_limit |
+---------------------------+
| 65535 |
+---------------------------+
1 row in set (0.00 sec)
mysql> select @@global.max_connections;
+--------------------------+
| @@global.max_connections |
+--------------------------+
| 300 |
+--------------------------+
1 row in set (0.00 sec)
mysql> set @@global.max_connections = 1000;
Query OK, 0 rows affected (0.00 sec)
mysql> select @@global.max_connections;
+--------------------------+
| @@global.max_connections |
+--------------------------+
| 300 |
+--------------------------+
1 row in set (0.00 sec)
mysql> show variables like 'open_files_limit';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| open_files_limit | 65535 |
+------------------+-------+
1 row in set (0.00 sec)
mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 300 |
+-----------------+-------+
1 row in set (0.01 sec)
mysql> set global max_connections = 1000;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 300 |
+-----------------+-------+
1 row in set (0.00 sec)
mysql> show grants for root@localhost;
+---------------------------------------------------------------------+
| Grants for root@localhost |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION |
+---------------------------------------------------------------------+
2 rows in set (0.00 sec)
更新:
cat /etc/mysql/mysql.conf.d/mysqld.cnf
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
log-error = /var/log/mysql/error.log
open_files_limit = 8192
max_connections = 1000
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
transaction-isolation=READ-COMMITTED
UPD 2 和解决方案:
我们找到了变量在数据库中被阻止的原因,在设置 Django 应用程序时我们有:
'init_command': 'SET default_storage_engine=INNODB, GLOBAL max_connections=300'
这不允许在 MySQL 中设置变量
答案1
更改此参数的最佳方法是编辑my.cnf
文件
[mysqld]
max_connections=1000
然后重新启动 MySQL 服务器。