> 데이터 베이스 > MySQL 튜토리얼 > MySQL JDBC中autoReconnectForPools的用途

MySQL JDBC中autoReconnectForPools的用途

WBOY
풀어 주다: 2016-06-07 16:31:53
원래의
3959명이 탐색했습니다.

有一个这样的场景,2台mysql数据库同步,正常的情况下一般只会连接其中的一台,如果其中一台down掉以后,应用程序能自动连接到另外一台,这样的场景和我上一篇文章描述的有所不同,详见: 《MySQL JDBC 集群》 一文,前面提到的是轮询访问,现在是一直访问一

有一个这样的场景,2台mysql数据库同步,正常的情况下一般只会连接其中的一台,如果其中一台down掉以后,应用程序能自动连接到另外一台,这样的场景和我上一篇文章描述的有所不同,详见:《MySQL JDBC 集群》一文,前面提到的是轮询访问,现在是一直访问一台,直到另外一台down机以后将会自动切换到另外一台上去,当然实现这样的场景你的应用程序必须使用JDBC的数据库连接池才会有效。

其实MySQL关于集群 的 JDBC参数还有很多,下面这些参数是我从MySQL官方网站上杂录的一部分,提供大家参考,

High Availability and Clustering. 

Property Name Definition Default Value Since Version
autoReconnect Should the driver try to re-establish stale and/or dead connections? If enabled the driver will throw an exception for a queries issued on a stale or dead connection, which belong to the current transaction, but will attempt reconnect before the next query issued on the connection in a new transaction. The use of this feature is not recommended, because it has side effects related to session state and data consistency when applications don't handle SQLExceptions properly, and is only designed to be used when you are unable to configure your application to handle SQLExceptions resulting from dead and stale connections properly. Alternatively, investigate setting the MySQL server variable "wait_timeout" to some high value rather than the default of 8 hours. false 1.1
autoReconnectForPools Use a reconnection strategy appropriate for connection pools (defaults to 'false') false 3.1.3
failOverReadOnly When failing over in autoReconnect mode, should the connection be set to 'read-only'? true 3.0.12
maxReconnects Maximum number of reconnects to attempt if autoReconnect is true, default is '3'. 3 1.1
reconnectAtTxEnd If autoReconnect is set to true, should the driver attempt reconnections at the end of every transaction? false 3.0.10
retriesAllDown When using loadbalancing, the number of times the driver should cycle through available hosts, attempting to connect. Between cycles, the driver will pause for 250ms if no servers are available. 120 5.1.6
initialTimeout If autoReconnect is enabled, the initial time to wait between re-connect attempts (in seconds, defaults to '2'). 2 1.1
roundRobinLoadBalance When autoReconnect is enabled, and failoverReadonly is false, should we pick hosts to connect to on a round-robin basis? false 3.1.2
queriesBeforeRetryMaster Number of queries to issue before falling back to master when failed over (when using multi-host failover). Whichever condition is met first, 'queriesBeforeRetryMaster' or 'secondsBeforeRetryMaster' will cause an attempt to be made to reconnect to the master. Defaults to 50. 50 3.0.2
secondsBeforeRetryMaster How long should the driver wait, when failed over, before attempting 30 3.0.2
selfDestructOnPingMaxOperations =If set to a non-zero value, the driver will report close the connection and report failure when Connection.ping() or Connection.isValid(int) is called if the connnection's count of commands sent to the server exceeds this value. 0 5.1.6
selfDestructOnPingSecondsLifetime If set to a non-zero value, the driver will report close the connection and report failure when Connection.ping() or Connection.isValid(int) is called if the connnection's lifetime exceeds this value. 0 5.1.6
resourceId A globally unique name that identifies the resource that this datasource or connection is connected to, used for XAResource.isSameRM() when the driver can't determine this value based on hostnames used in the URL 5.0.1

–end–

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿