About setting the Mysql link URL parameter _mysql

Source: Internet
Author: User
Recently tidied up the internet about the MySQL link url parameter settings, there is not the right place I hope you will advise:

The MySQL JDBC URL format is as follows:

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

Some of the most important parameters are commonly used:

The parameter name parameter describes the minimum version requirement for the default value
User database username (for connecting to database) all versions
PassWord user password (for connecting to database) all versions
Useunicode whether the Unicode character set is used, and if the parameter characterencoding is set to gb2312 or GBK, this parameter value must be set to true false 1.1g
characterencoding Specifies the character encoding when the 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 a reconnection policy for the database connection pool false 3.1.3
Failoverreadonly the connection is set to read-only after the automatic reconnection is successful? True 3.0.12
Maxreconnects AutoReConnect is set to True, retry the connection 3 1.1 times
Initialtimeout AutoReConnect is set to true, the time interval between two times, units: seconds 2 1.1
Timeout, in milliseconds, between ConnectTimeout and the database server when establishing a socket connection. 0 means never timeout, applicable to 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 Code code 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 Code code as follows:

Autoreconnect=true&failoverreadonly=false

It should be noted 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 Code code as follows:

jdbc:mysql://localhost:3306/test?user=root&password=&useunicode=true&characterencoding=utf8& Autoreconnect=true&failoverreadonly
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.