How To Enable/ Disable Auto Reconnect in MySQL如何啟用/禁用自動重新在MySQL

What is auto reconnect in MySQL?什麼是自動重新在MySQL ?
The MySQL client library can perform an automatic reconnect to the server if it finds that the connection is down when you attempt to send a statement to the server to be executed.該MySQL客戶端庫可以執行自動重新連接到服務器如果它發現該連接是下跌當您試圖發送一份聲明,服務器被處決。 In this case, the library tries once to reconnect to the server and send the statement again.在這種情況下,圖書館的嘗試,一旦重新連接到服務器並發送的聲明。
Automatic reconnection can be convenient because you need not implement your own reconnect code, but if a reconnection does occur, several aspects of the connection state are reset and your application will not know about it.自動重,可以方便,因為你不用推行自己重新代碼,但如果重新出現,幾個方面的連接狀態重置和您的申請將不知道它。 This is extremely useful if you long running persistent connections to the database.這是非常有用的,如果你長時間運行的持久連接到數據庫。 Also if you have too many sql queries / use connection pool etc. auto reconnect is a handy feature.此外,如果您有太多的SQL查詢/使用連接池等自動重新連接是一個很方便的功能。 Let’s look at how to enable / disable auto reconnect in MySQL and what are the side-effects of enabling auto reconnect.讓我們看看如何啟用/禁用自動重新在MySQL和什麼是產生的副作用,使自動重新連接。
How to enable MySQL client auto reconnect如何使MySQL客戶端自動重新
my_bool reconnect = 1; my_bool重新= 1 ;
mysql_options(&mysql, MYSQL_OPT_RECONNECT, &reconnect); mysql_options ( & MySQL中, mysql_opt_reconnect , &重新) ;
What are the side-effects of MySQL auto reconnect?有什麼副作用的MySQL自動重新?
- Any active transactions are rolled back and autocommit mode is reset.任何積極的交易回滾和autocommit模式是重置。
- All table locks are released.所有表鎖定釋放。
- All TEMPORARY tables are closed (and dropped).所有的臨時表是封閉(和下降) 。
- Session variables are reinitialized to the values of the corresponding variables.會話變量reinitialized ,以價值相應的變數。 This also affects variables that are set implicitly by statements such as SET NAMES.這也影響了變數,是一套由含蓄的聲明,例如訂定的名稱。
- User variable settings are lost.用戶變量的設置都將丟失。
- Prepared statements are released.編寫報表公佈。
- HANDLER variables are closed.處理變量均停課。
- The value of LAST_INSERT_ID() is reset to 0.價值last_insert_id ( )是重置為0 。
- Locks acquired with GET_LOCK() are released.取得的鎖定與get_lock ( )公佈。
- mysql_ping() does not attempt a reconnection if the connection is down. mysql_ping ( )並不試圖重新如果連線。 It returns an error instead.它返回一個錯誤。
How to disable MySQL client auto reconnect如何禁用MySQL客戶端自動重新
In view of the side-effects you may want to disable auto reconnect.在檢視的副作用,您可能需要禁用自動重新連接。 In MySQL version 5.1 and above auto reconnect is disabled by default.在MySQL 5.1版及以上的自動重新連接是默認情況下禁用。 In any version you can disable auto reconnect with the following PHP code:在任何版本,您可以禁用自動重新與下列PHP代碼:
my_bool reconnect = 0; my_bool重新= 0 ;
mysql_options(&mysql, MYSQL_OPT_RECONNECT, &reconnect); mysql_options ( & MySQL中, mysql_opt_reconnect , &重新) ;
Filed under提起下 Database數據庫 , , Enterprise Software企業軟件 , , Headline News頭條新聞 , , How To如何 , , Java Software Java軟件 , , MySQL MySQL的 , , Open Source Software開放源碼軟件 , , PHP PHP的 , , Programming編程 , , RDBMS RDBMS的 , , Tech Note技術說明 | |
| |
RSS 2.0 2.0 | |
Trackback Trackback跟踪 this Article |此文章|
Email this Article電子郵件此文章
You may also like to read您也可以想讀 |





October 17th, 2007 at 1:25 pm 2007年10月17日在下午1時25分
That’s not PHP code這不是PHP代碼
C/C++ perhaps.炭/炭+也許。
October 18th, 2007 at 1:08 pm 2007年10月18日在下午1時08分
It is PHP code.這是PHP代碼。 Check the fine manual檢查罰款手冊
May 23rd, 2008 at 4:15 pm 2008年5月23日在下午4時15分
There’s no mysql_options() command listed anywhere in PHP documentation that I can find (trying to use it gives an ‘undefined function’ error).有沒有mysql_options ( )命令中列出的任何地方,在PHP文件,我可以找到(試圖利用它給出了一個'未定義的功能'的錯誤) 。 my_bool is definitely not a PHP variable type. my_bool絕對不是PHP變量的類型。 PHP variables also need $’s, of which you have none. PHP變量還需要元,奇摩,其中你有沒有。 I’m sorry, but this is NOT php code.我很抱歉,但是這不是PHP代碼。
You provide useful explanation of auto-reconnection functionality, but please don’t mislead people by claiming it’s useful code for PHP developers.你提供有用的解釋,自動重功能,但請你不要誤導人民,聲稱它的有用的代碼為PHP開發。