MySQL的最大連線數一直被設成214
2016-12-02 17:45:19
問題
在 /etc/mysql/my.cnf 中加上的max_connections的設定
/etc/mysql/my.cnf[mysqld]
max_connections=10000
但在查看實際的設定值仍然是214。
mysql> show global variables like '%max_connecti%';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 214 |
+-----------------+-------+
1 row in set (0.01 sec)
解法
造成這個問題是有兩個原因,一是系統的「一個process最大可開起的檔案數」的值預設是1024,可以使用 ulimit -a,或是從mysql下面的指令看到這個值:
mysql> show global variables like '%open_files_limit%';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| open_files_limit | 1024 |
+------------------+-------+
1 row in set (0.00 sec)
這個值會限定MySQL同時連線的數量,所以要先改這個數值。這是linux系統本身的設定,所以必須使用sudo將下面的設定加入到/etc/security/limits.conf這個檔案。
/etc/security/limits.conf* soft nofile 65536
* hard nofile 65536
當設定完成,可以重啟系統讓設定值生效。第二個原因是在啟動mysql的時候要解除open file的限制,方法是在啟動mysql的service檔裡加上LimitNOFILE=65535的設定:
/lib/systemd/system/mysql.serviceLimitNOFILE=65535
當這兩步做完,重啟mysql之後,就可以看到正確的連線數設定了。
mysql> show global variables like '%max_connecti%';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 10000 |
+-----------------+-------+
1 row in set (0.01 sec)
mysql> show global variables like '%open_files_limit%'; +------------------+-------+ | Variable_name | Value | +------------------+-------+ | open_files_limit | 65535 | +------------------+-------+ 1 row in set (0.00 sec)
=====
前面做完如果沒有用, 可以用set GLOBAL max_connections=200;
去設定最大的max connection 數量, 只是目前還是不知道為什麼寫在 mysqld的啟動定檔案沒有校,
可是用手去改是有用的
#查詢目前MySQL Process 狀況mysql> show processlist; #查詢目前MySQL max connectionsmysql> show variables like ‘max_connections’;#設定MySQL max connectionsmysql> set GLOBAL max_connections=200; 但因為MySQL重開後, max_connections的設定值就會被清掉可在 /etc/my.cnf裡設定 set-variable = max_connections=200存檔後,重新啟動MySQL即可
留言
張貼留言