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.它返回一個錯誤。

Source來源

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 , &重新) ;