MySQL JDBC URL format for connector/j The following example:
Jdbc:mysql://[host][,failoverhost ...] [:p ort]/[database]»
[? PROPERTYNAME1] [=propertyvalue1] [&propertyname2] [=propertyvalue2] ...
Jdbc:mysql://[host:port],[host:port].../[database]»
[? PROPERTYNAME1] [=propertyvalue1] [&propertyname2] [=propertyvalue2] ...
Instance:
Jdbc:mysql://localhost:3306/sakila?profilesql=true
Only a few important parameters are listed, as shown in the following table:
Parameter Name parameter description Minimum default version requires user database username (used to connect to database) All Versions password user passwords (used to connect to the database) All Versions Useun Icode 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 False 1.1gcharacterEncoding Specifies the character encoding when Useunicode is set to true. For example, can be set to gb2312 or GBK false 1.1gautoReconnect Is the connection automatically reconnected when the database connection is interrupted abnormally? False 1.1autoReconnectForPools whether to use a reconnection policy against the database connection pool False 3.1.3failOverReadOnly Is the connection set to read-only after the automatic reconnection is successful? True 3.0.12maxReconnects when AutoReConnect is set to true, the number of times the connection is retried 3 1.1initialTimeout AutoReConnect When set to True, the time interval between two re-interconnects, units: seconds 2 1.1connectTimeout and database server establish Socke T timeout, in milliseconds, when connecting. 0 means never timeout, for JDK 1.4 and later 0 3.0.1socketTimeout Socke T 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:
jdbc:mysql://localhost:3306/test?user=root&password=&useunicode=true&characterencoding=gbk& 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=gbk
&autoreconnect=true&failoverreadonly=false
MySQL SQL statement alias does not take effect: useoldaliasmetadatabehavior instance:
Jdbc:mysql://localhost/openemm?useunicode=yes&characterencoding=utf-8&useoldaliasmetadatabehavior=true
Where: Dbc:mysql://localhost/openemm? This represents the database link address,
Useunicode=yes&characterencoding=utf-8 This delegate allows the user to set the database encoding themselves and set it to UTF-8 useoldaliasmetadatabehavior= True this represents a database where aliases are allowed
Mysql JDBC URL parameter Description useunicode=true&characterencoding=utf-8