本文來源于網頁設計愛好者web開發社區http://www.html.org.cn收集整理,歡迎訪問。mysql的最大連接數默認是100, 這個數值對于并發連接很多的數據庫應用是遠遠不夠的,當連接請求大于默認連接數后,就會出現無法連接數據庫的錯誤,因此我們需要把它適當調大一些, 有兩種辦法可以修改最大連接數,一種是修改safe_mysqld,另一種是直接修改原代碼并重新編譯。下面我們就分別介紹這兩種方法:
1.修改safe_mysqld
找到safe_mysqld編輯它,找到mysqld啟動的那兩行,在后面加上參數 :
-o max_connections=1000
例如 :(其中前面有---的是原來的內容,而+++是修改過以后的)
--- safe_mysqld.orig mon sep 25 09:34:01 2000
+++ safe_mysqld sun sep 24 16:56:46 2000
@@ -109,10 +109,10 @@
if test "$#" -eq 0
then
nohup $ledir/mysqld --basedir=$my_basedir_version --datadir=$datadir
- --skip-locking >> $err_log 2>&1
+ --skip-locking -o max_connections=1000 >> $err_log 2>&1
else
nohup $ledir/mysqld --basedir=$my_basedir_version --datadir=$datadir
- --skip-locking "$@" >> $err_log 2>&1
+ --skip-locking "$@" -o max_connections=1000 >> $err_log 2>&1
fi
if test ! -f $pid_file # this is removed if normal shutdown
then
然后關閉mysql重啟它,用
/mysqladmin所在路徑/mysqladmin -uroot -p variables
輸入root數據庫賬號的密碼后可看到
| max_connections | 1000 |
即新改動已經生效。
2.修改原代碼
解開mysql的原代碼,進入里面的sql目錄修改mysqld.cc找到下面一行:
{ "max_connections", (long*) &max_connections,100,1,16384,0,1},
把它改為:
{ "max_connections", (long*) &max_connections,1000,1,16384,0,1},
存盤退出,然后./configure ;make;make install可以獲得同樣的效果。