About the setting of MySql link url parameters

Recently, I have sorted out the settings of MySql link url parameters on the Internet. If there is any incorrect place, I hope you can give me more advice: The

mysql JDBC URL format is as follows:

jdbc:mysql://[host:port],[host:port].../ [database][?Parameter name 1][=parameter value 1][¶meter name 2][=parameter value 2]...

Several commonly used more important parameters:

parameter name parameter description default value The minimum version requires
user Database username (used to connect to the database) All versions
passWord User password (used to connect to the database) All versions
useUnicode Whether to use the Unicode character set, if the parameter characterEncoding is set to gb2312 or gbk, the value of this parameter must be set to true false 1.1g
characterEncoding When Specifies the character encoding when useUnicode is set to true. For example, it can be set to gb2312 or gbk false 1.1g
autoReconnect When the database connection is interrupted abnormally, will it automatically reconnect? false 1.1
Does autoReconnectForPools use the reconnection strategy for database connection pools false 3.1.3
failOverReadOnly After the automatic reconnection is successful, is the connection set to read-only? true 3.0.12
maxReconnects autoReconnect set to true, the number of times to retry the connection 3 1.1
When initialTimeout autoReconnect is set to true, the time interval between two reconnects, in seconds 2 1.1
connectTimeout The timeout when establishing a socket connection with the database server, in milliseconds. 0 means never timeout, applicable to JDK 1.4 and later versions 0 3.0.1
socketTimeout socket operation (read and write) timeout, unit: milliseconds. 0 means never timeout 0 3.0.1

Corresponding to the Chinese environment, usually the mysql connection URL can be set as: 

 
jdbc:mysql://localhost:3306/test?user=root&password=&useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
In the case of using a database connection pool, it is best to set the following two parameters:

 
autoReconnect=true&failOverReadOnly=false
It should be noted that in the xml configuration file, the & symbol in the url needs to be escaped to &. For example, when configuring the database connection pool in tomcat's server.xml, the mysql jdbc url sample is as follows:

 
jdbc:mysql://localhost:3306/test?user=root&password=&useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325649299&siteId=291194637