天天看點

【MySql】修改max_connections 參數的方法

  開發說應用不能連接配接資料庫,檢視資料庫連接配接資訊已經超過最大允許連接配接數

1 資料庫系統允許的最大可連接配接數max_connections。該參數是可以設定的。如果不設定,預設是100。最大是16384。 

2 資料庫目前的連接配接線程數threads_connected。該參數是動态變化的。 

如果 threads_connected == max_connections 時,資料庫系統就不能提供更多的連接配接數了,這時,如果程式還想建立連接配接線程,資料庫系統就會拒絕,結果如開發所說連接配接不了。如何修改max_connections呢?

方法1 在會話中修改

mysql> show variables like '%max_connections%'; 

+-----------------+-------+

| variable_name   | value |

| max_connections | 151 |

1 row in set (0.00 sec)

mysql> set global max_connections=14000;

query ok, 0 rows affected (0.01 sec)

| max_connections | 14000 |

方法2 在my.conf 參數中修改,不過需要重新啟動mysql 服務!不推薦

方法3 在編譯資料庫時就進行以centos 4.4 下面的mysql 5.0.33 手工編譯版本為例說明:

  vi /usr/local/mysql/bin/mysqld_safe

  找到safe_mysqld編輯它,找到mysqld啟動的那兩行,在後面加上參數 :

  -o max_connections=1500

  具體一點就是下面的位置:

  用紅字特别說明:

  then $nohup_niceness $ledir/$mysqld

  $defaults --basedir=$my_basedir_version

  --datadir=$datadir $user_option

  --pid-file=$pid_file

  --skip-external-locking

  >> $err_log 2>&1 else

  eval "$nohup_niceness $ledir/$mysqld

  --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},

  把它改為:

  (gptr*) &max_connections, 0, get_ulong, required_arg, 1500, 1, 16384, 0, 1,

  存盤退出,然後./configure ;make;make install可以獲得同樣的效果。

方法3 摘自 http://www.cnblogs.com/nzperfect/archive/2009/06/29/1513319.html