mysql連接數是一個機器整性能的提供了,配置不好網站經常會不開,配置好了機器能用到極致了,下面我來介紹mysql連接數具體方法.
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 --Vevb.com
- 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. --Vevb.com
- max_connections=100
將它改成更大的數值,如500.
注意:
1、雖然這里寫的32000,但實際MySQL服務器允許的最大連接數16384.
2、除max_connections外,上述其他配置應該根據你們系統自身需要進行配置,不必拘泥.
3、添加了最大允許連接數,對系統消耗增加不大.
4、如果你的mysql用的是my.ini作配置文件,設置類似,但設置的格式要稍作變通.
5、在windows 系統中 max_connections連接數據需要根據自己機器性能來設置,不是越大越好.
新聞熱點
疑難解答