MySQL 預設的最大串連數為 100,可以在 mysql 用戶端使用以下命令查看
mysql> show variables like 'max_connections';
此命令將得到類似以下的輸出結果:
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 2000 |
+-----------------+-------+
1 row in set (0.00 sec)
或利用 mysqladmin 查看當前最大串連數
mysqladmin -uusername -ppassword variables |find "max_con"
如:
C:mysqlbin>mysqladmin -uroot -p variables | find "max_con"
Enter password:
| max_connections | 100
| max_connect_errors | 10
要對 mysql 的最大串連數進行修改,只需要在 my.cnf 設定檔裡面修改 max_connections 的值,然後重啟 mysql 就行。
[mysqld]
port=3306
#socket=MySQL
skip-locking
set-variable = key_buffer=16K
set-variable = max_allowed_packet=1M
set-variable = thread_stack=64K
set-variable = table_cache=4
set-variable = sort_buffer=64K
set-variable = net_buffer_length=2K
set-variable = max_connections=32000
如果是在windows中增加方法更簡單
1,修改my.ini
# The maximum amount of concurrent sessions the MySQL server will
# allow. One of these connections will be reserved for a user with
# SUPER privileges to allow the administrator to login even if the
# connection limit has been reached.
max_connections=100
將它改成更大的數值,如500
注意:
1、雖然這裡寫的32000。但實際MySQL伺服器允許的最大串連數16384;
2、除max_connections外,上述其他配置應該根據你們系統自身需要進行配置,不必拘泥;
3、添加了最大允許串連數,對系統消耗增加不大。
4、如果你的mysql用的是my.ini作設定檔,設定類似,但設定的格式要稍作變通。
5、在windows 系統中 max_connections串連資料需要根據自己機器效能來設定,不是越大越好。