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] ...
- MySQL in the high version needs to indicate whether to make an SSL connection after the URL plus usessl=true or write the program will have warning
Some of the more important parameters are commonly used:
Parameter Name parameter description
- User database username (used to connect to database)
- PassWord user password (used to connect to database)
- Useunicode whether the Unicode character set is used, the value of this parameter must be set to True if the parameter characterencoding is set to gb2312 or GBK
- AutoReConnect is the connection automatically reconnected when the database connection is interrupted abnormally?
- Autoreconnectforpools whether to use a reconnection policy for database connection pooling
- Maxreconnects AutoReConnect is set to true, the number of times to retry the connection
- Failoverreadonly is the connection set to read-only after the auto-reconnect is successful?
For the Chinese environment, the MySQL connection URL can usually be set to:
- 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
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:
- Jdbc:mysql://localhost:3306/test?user=root&password=&useunicode=true&characterencoding =utf8&autoreconnect=true
MySQL link URL parameter detailed