Setting the MySql link url parameter

  • 2020-06-12 10:49:36
  • OfStack

Recently, I have sorted out 1 set of MySql link url parameters on the Internet. I hope you can give me more advice if there are some incorrect places:

mysql JDBC URL format:

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

Several important parameters commonly used:

Parameter name Parameter specifies the default minimum version requirement
user database username (used to connect to the database) for all versions
passWord user password (used to connect to the database) for all versions
Whether useUnicode is using the Unicode character set. If the parameter characterEncoding is set to gb2312 or gbk, the parameter value must be set to true false 1.1g
When useUnicode is set to true, specify the character encoding. For example, it can be set to gb2312 or gbk false 1.1g
Does autoReconnect automatically reconnect when a database connection is aborted? false 1.1
Whether autoReconnectForPools USES a reconnect strategy for the database connection pool false 3.1.3
Is the connection set to read-only after failOverReadOnly reconnects successfully? true 3.0.12
The number of retries when maxReconnects autoReconnect is set to true 3 1.1
When initialTimeout autoReconnect is set to true, the time interval between two reconnections, unit: seconds 2, 1.1
Timeout in milliseconds for connectTimeout to establish an socket connection with the database server. 0 means never timeout and is available for JDK 1.4 and later versions 0, 3.0.1
socketTimeout socket operation (read and write) timeout in milliseconds. 0 means never timeout 0 3.0.1

Corresponding to Chinese environment, mysql connection URL can be set as:
 
jdbc:mysql://localhost:3306/test?user=root&password=&useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false 

When using a database connection pool, it is best to set the following two parameters:
 
autoReconnect=true&failOverReadOnly=false 

Note that in the xml configuration file, in url & The symbol needs to be escaped & amp; . For example, when configuring database connection pool in tomcat's ES82en.xml, mysql jdbc url example:
 
jdbc:mysql://localhost:3306/test?user=root&password=&useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly 

Related articles: