MySQL api自动重连的问题

| No Comments | No TrackBacks

在mysql 4.1中,无法设置是否启用自动重连机制,即默认总是会自动重连。


[mysqld] init_connect='SET NAMES utf8'


Google 后有相关资料:



How to disable MySQL client auto reconnect

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. In any version you can disable auto reconnect with the following PHP code:
my_bool reconnect = 0;
mysql_options(&mysql, MYSQL_OPT_RECONNECT, &reconnect);



Mysql 4.1的手册中的相关说明:


17.7.13. Controlling Automatic Reconnect Behavior

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. In this case, the library tries once to reconnect to the server and send the statement again.

Some client programs might provide the capability of controlling automatic reconnection. For example, mysql reconnects by default, but the --skip-reconnect option can be used to suppress this behavior.

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. The connection-related state is affected as follows:

·         Any active transactions are rolled back and autocommit mode is reset.

·         All table locks are released.

·         All TEMPORARY tables are closed (and dropped).

·         Session variables are reinitialized to the values of the corresponding variables. 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.

Locks acquired with GET_LOCK() are released.


No TrackBacks

TrackBack URL:

Leave a comment


May 2016

Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        

About this Entry

This page contains a single entry by 谷多 published on April 14, 2009 12:17 AM.

MySQL数据校验时需要注意的问题:mysql 4 和 mysql5对varchar的处理方式不同 was the previous entry in this blog.

9个月+6天 73.7cm 10kg is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.