The following articles mainly introduce the format of MySQL jdbc url and detailed parsing of its related parameters. If you are interested in the format of MySQL jdbc url and the actual application of parameters, you can browse the following content. Recently, I encountered such problems in actual operations, as shown below,
Report
- at com.MySQL.jdbc.MySQLIO.readFully(MySQLIO.java:1905)
- at com.MySQL.jdbc.MySQLIO.reuseAndReadPacket(MySQLIO.java:2351)
- at com.MySQL.jdbc.MySQLIO.checkErrorPacket(MySQLIO.java:2862)
- at com.MySQL.jdbc.MySQLIO.sendCommand(MySQLIO.java:1571)
- at com.MySQL.jdbc.MySQLIO.sqlQueryDirect(MySQLIO.java:1666)
- at com.MySQL.jdbc.Connection.execSQL(Connection.java:2988)
- at com.MySQL.jdbc.Connection.execSQL(Connection.java:2917)
- at com.MySQL.jdbc.Statement.executeQuery(Statement.java:824)
- at com.zycy.db.DbTrans.executeQuery(DbTrans.java:127)
This error is fine after the Tomcat service is restarted, but this problem occurs one night later.
The URL format of MySQL JDBC is as follows:
Jdbc: MySQL: // [host: port], [host: port].../[database] [? Parameter Name 1] [= parameter value 1] [& parameter name 2] [= parameter value 2]...
Common important parameters:
Parameter name parameter description default value minimum version requirements
User database username used to connect to the database) All versions
Password user password used to connect to the database) All versions
Whether useUnicode uses the Unicode character set. If the characterEncoding parameter 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, you can set it to gb2312 or gbk false 1.1g.
Is autoReconnect automatically reconnecting when the database connection is interrupted abnormally? False 1.1
Whether autoReconnectForPools uses the reconnection policy for the database connection pool false 3.1.3
After failOverReadOnly is automatically reconnected, is the connection set to read-only? True 3.0.12
When maxReconnects autoReconnect is set to true, the number of retries is 3 1.1.
The time interval between two reconnections when initialTimeout autoReconnect is set to true. Unit: Second 2 1.1
The timeout value for establishing a socket connection between connectTimeout and the database server, in milliseconds. 0 indicates never timeout, applicable to JDK 1.4 and later version 0 3.0.1
SocketTimeout socket operation (read/write) Timeout, in milliseconds. 0 indicates never timeout. 0 3.0.1
The connection URL of MySQL can be set:
- jdbc:MySQL://localhost:3306/test?user=root&password=&useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
When using the 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 must be converted to & amp ;. For example, when you configure the database connection pool in tomcat server. xml, the MySQL jdbc url sample is as follows:
- jdbc:MySQL://localhost:3306/test?user=root&password=&useUnicode=true&characterEncoding=utf8&autoReconnect
The above content is an introduction to the MySQL jdbc url. I hope you will get some benefits.