茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1672184 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
IMG_60D_00056.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

DB研討會 : [分享]MySql Too many connections 的錯誤控制

發表者 討論內容
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[分享]MySql Too many connections 的錯誤控制

B.5.2.7 Too many connections

If you get a Too many connections error when you try to connect to the mysqld server, this means that all available connections are in use by other clients.

The number of connections permitted is controlled by the max_connections
system variable. The default value is 151 to improve performance when MySQL is used with the Apache Web server. (Previously, the default was 100.) If you need to support more connections, you should set a larger value for this variable.

mysqld actually permits max_connections+1 clients to connect. The extra connection is reserved for use by accounts that have the SUPER privilege. By granting the
SUPER privilege to administrators and not to normal users (who should not need it), an administrator can connect to the server and use SHOW PROCESSLIST to diagnose problems even if the maximum number of unprivileged clients are connected. See Section 13.7.5.30, “ SHOW PROCESSLIST Syntax”.


The maximum number of connections MySQL can support depends on the quality of the thread library on a given platform, the amount of RAM available, how much RAM is used for each connection, the workload from each connection, and the desired response time. Linux or Solaris should be able to support at 500 to 1000 simultaneous connections routinely and as many as 10,000 connections if you have many gigabytes of RAM available and the workload from each is low or the response time target undemanding. Windows is limited to (open tables × 2 + open connections) < 2048 due to the Posix compatibility layer used on that platform.

Increasing open-files-limit may be necessary. Also see
Section 2.5, “Installing MySQL on Linux”, for how to raise the operating system limit on how many handles can be used by MySQL.


比較吸引冷日目光的則是回覆的部份!
我們看到兩條回覆很有意思,回覆一:


Posted by Rob Williams on April 27 2004 6:08am [Delete] [Edit]

Detect "Too many connections" error and show alternate web page


$link = mysql_connect("localhost", "mysql_user", "mysql_password");
if (mysql_errno() == 1203) {
// 1203 == ER_TOO_MANY_USER_CONNECTIONS (mysqld_error.h)
header("Location: http://your.site.com/alternate_page.php");
exit;
}
?>

冷日說明:
這個是檢測是否有過多連線的一段 Code,我們平常寫 php 就會把 connect 另外寫,只要在裡面檢查一下是否 error 並且看他的 error code 我們就可以進行錯誤控制!
註:本處是重新導向到自己寫的某頁進行錯誤顯示。


回覆二:


Posted by Femi Hasani on May 29 2004 12:11am [Delete] [Edit]


ini_set('display_errors', '0');
$link = mysql_connect("localhost", "user", "pass");
if (mysql_errno() == 1040 OR mysql_errno() == 1203) {
define("DB_HOST", "some_ip:3306");//remote
define("DB_NAME", "db"); //database_name
define("DB_USER", "user"); //database user name
define("DB_PASSWORD","pass"); //database (user) password
}
else
{
define("DB_HOST", "localhost");
define("DB_NAME", "db_name2"); //database_name
define("DB_USER", "user"); //database user name
define("DB_PASSWORD","pass"); //database (user) password
}
ini_set('display_errors', '1');
//by feha at www.vision.to
?>

冷日說明:
這個則是進行負載平衡!
他檢測到錯誤碼 1040 或 1203 時,他就會連網另外一個資料庫!這樣就可以分擔主資料庫負載!
註:他還特別把錯誤顯示先關掉,等到重新連線完成後才把錯誤顯示打開,很細心。


這兩個回覆的程式碼對於 MySql 的錯誤控制都是值得學習的!
原文出處: MySQL :: MySQL 5.5 Reference Manual :: B.5.2.7 Too many connections
前一個主題 | 下一個主題 | 頁首 | | |



Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|