MySQL 修改最大鏈接數

方法一:
進入MySQL安裝目錄 打開MySQL配置文件 my.ini 或 my.cnf查找 max_connections=100 修改成 max_connections=1000 服務裏重起MySQL便可
方法二:
MySQL最大鏈接數默認是100客戶端登陸:
MySQL -uusername -ppassword
設置新的MySQL最大鏈接數爲200:
MySQL> set GLOBAL max_connections=200
顯示當前運行的Query:
MySQL> show processlist
顯示當前狀態:
MySQL> show status
退出客戶端:MySQL> exit
查看當前MySQL最大鏈接數:MySQLadmin -uusername -ppassword variables
方法三:
以centos 4.4 下面的MySQL 5.0.33 手工編譯版本爲例說明:
vi /usr/local/MySQL/bin/MySQLd_safe
找到safe_MySQLd編輯它,找到MySQLd啓動的那兩行,在後面加上參數 :
-O max_connections=1500
具體一點就是下面的位置:sql

then $NOHUP_NICENESS $ledir/$MySQLD
$defaults --basedir=$MY_BASEDIR_VERSION
--datadir=$DATADIR $USER_OPTION
--pid-file=$pid_file
--skip-external-locking
-O max_connections=1500
>> $err_log 2>&1 else
eval "$NOHUP_NICENESS $ledir/$MySQLD
$defaults --basedir=$MY_BASEDIR_VERSION
--datadir=$DATADIR $USER_OPTION
--pid-file=$pid_file
--skip-external-locking $args
-O max_connections=1500 >>
$err_log 2>&1"

保存。

# service MySQLd restart
# /usr/local/MySQL/bin/MySQLadmin -uroot -p variables

輸入root數據庫帳號的密碼後可看到

max_connections 1500 即新改動已經生效。

還有一種方法,

修改原代碼:

解開MySQL的原代碼,進入裏面的sql目錄修改MySQLd.cc找到下面一行:

{"max_connections", OPT_MAX_CONNECTIONS,
"The number of simultaneous clients allowed.", (gptr*) &max_connections,
(gptr*) &max_connections, 0, GET_ULONG, REQUIRED_ARG, 100, 1, 16384, 0, 1,
0},

把它改成:

{"max_connections", OPT_MAX_CONNECTIONS,
"The number of simultaneous clients allowed.", (gptr*) &max_connections,
(gptr*) &max_connections, 0, GET_ULONG, REQUIRED_ARG, 1500, 1, 16384, 0, 1,
0},

存盤退出,而後./configure ;make;make install能夠得到一樣的效果。數據庫

相關文章
相關標籤/搜索