The MySQL JDBC URL format is as follows:
jdbc:mysql://[host:port],[host:port].../[database][. Parameter name 1][= argument value 1][& parameter name 2][= argument value 2] ...
Some of the more important parameters are commonly used:
Parameter name parameter Description default minimum version requirement
User database username (for connection to database) all versions
PassWord User password (for connection to database) all versions
Useunicode whether the Unicode character set is used, if the parameter characterencoding is set to gb2312 or GBK, the value of this parameter must be set to true false 1.1g
characterencoding Specifies the character encoding when Useunicode is set to true. For example, can be set to gb2312 or GBK false 1.1g
AutoReConnect is the connection automatically reconnected when the database connection is interrupted abnormally? False 1.1
Autoreconnectforpools whether to use the reconnection policy against the database connection pool false 3.1.3
Failoverreadonly is the connection set to read-only after the auto-reconnect is successful? True 3.0.12
Maxreconnects AutoReConnect is set to true, number of retry Connections 3 1.1
Initialtimeout AutoReConnect set to True, the time interval between two re-interconnects, in seconds 2 1.1
ConnectTimeout time-out, in milliseconds, when a socket connection is established with the database server. 0 means never timeout, for JDK 1.4 and later 0 3.0.1
Sockettimeout socket operation (read-write) timeout, in milliseconds. 0 means never timeout 0 3.0.1
For the Chinese environment, the MySQL connection URL can usually be set to:
Copy CodeThe code is as follows:
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:
Copy CodeThe code is as follows:
Autoreconnect=true&failoverreadonly=false
Note that in the XML configuration file, the & symbol in the URL needs to be escaped to &. For example, when configuring a database connection pool in Tomcat's server.xml, the MySQL JDBC URL sample is as follows:
Copy CodeThe code is as follows:
jdbc:mysql://localhost:3306/test?user=root&password=&useunicode=true&characterencoding=utf8& Autoreconnect=true&failoverreadonly
Http://www.jb51.net/article/47764.htm
Settings for MySQL link URL parameters