当前位置:网站首页>MySQL -- time zone / connector / driver type
MySQL -- time zone / connector / driver type
2022-07-02 10:15:00 【It blade out of sheath】
brief introduction
In this paper, MySQL How to modify the time zone ; Driver version ; Connector and driver version ; Type of drive .
The time zone
error message
java.sql.SQLException: The server time zone value '???ú±ê×??±??' is unrecognized or represents more than one time zone
resolvent
Change the time zone . Modify the following server or client url The connected time zones are OK .
Law 1: Modify the server time zone
The way 1: Command to change
set global time_zone = '+8:00'; ## modify mysql The global time zone is Beijing time , That is where we are 8 District
set time_zone = '+8:00'; ## Modify the current session time zone
flush privileges; ## Immediate effect
The way 2: Modify the configuration file
【linux:my.cnf,windows:my.ini】
stay [mysqld] Add the lower line to the area :
default-time_zone = '+8:00'
- 1.
restart MySQL service .
Law 2: Modify the client url Connect to the time zone
serverTimezone=xxx
UTC: World equilibrium time ( London time )( Earlier than China 8 Hours )
GMT: GMT ( It's also London time , and UTC The same effect )
CST: US China region (-6)
GMT%2B8: Beijing time. (+8)
Asia/Shanghai: Shanghai time (+8)( Equal to Beijing time )
Asia/Hongkong: Hong Kong time (+8)( Equal to Beijing time )
Try to follow this order :characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
Refer to the following table for the configuration method “ Driver version ”.
Driver version
com.mysql.jdbc.Driver yes mysql-connector-java 5 Of ,com.mysql.cj.jdbc.Driver yes mysql-connector-java 6 Of .
because springboot Support loose matching , therefore utf8 And UTF-8 It's the same .
Mysql5 Of application.yml To configure
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/mp?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
password: xxx
username: yyy
jpa:
hibernate:
ddl-auto: none
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
Mysql6 And above application.yml To configure
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/mp?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
password: xxx
username: yyy
jpa:
hibernate:
ddl-auto: none
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
Connector and driver version
Warning 1: edition
If mysql-connector-java(pom.xml The dependent version of ) With 6.0 The above , but driver Use or com.mysql.jdbc.Driver, I'll call the police :
Loading class 'com.mysql.jdbc.Driver'. This is deprecated. The new driver class is 'com.mysql.cj.jdbc.Driver'.
The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
- 1.
- 2.
At this time, we need to put com.mysql.jdbc.Driver Change it to com.mysql.cj.jdbc.Driver
Warning 2:SSL
WARN: Establishing SSL connection without server’s identity verification is not recommended.
According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn’t set.
For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false’.
You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
- 1.
- 2.
- 3.
- 4.
translate :
Server authentication is not recommended to establish SSL Connect .
If not explicitly set ,MySQL 5.5.45+, 5.6.26+ and 5.7.6+ By default, the version requires SSL Connect .
In order to comply with the current not used SSL Connected applications ,verifyServerCertificate Property is set to ’false’.
If you don't need to use SSL Connect , You need to go through the settings useSSL=false To explicitly disable SSL Connect . If you need to use SSL Connect , To provide a truststore for server certificate validation , And set up useSSL=true.
Drive type
brief introduction
There are three types , as follows :
- Class.forName("com.mysql.jdbc.Driver");( recommend )
- new com.mysql.jdbc.Driver() ;
- em.setProperty("jdbc.drivers","com.mysql.jdbc.Driver");
1. Class.forName("com.mysql.jdbc.Driver"); // Load database driver
- Class.forName("com.mysql.jdbc.Driver"); // Load database driver
- String url="jdbc:mysql://localhost:3306/databasename"; // Database connection sub protocol
- Connection conn=DriverManager.getConnection(url, "username", "password");
This method is because the parameter is a string , So it's easy to modify , Portability is strong . The most common way to register , It's also recommended .
2. new com.mysql.jdbc.Driver() ; // establish driver object , Load database driver
- new com.mysql.jdbc.Driver(); // establish driver object , Load database driver
- String url="jdbc:mysql://localhost:3306/databasename"; // Database connection sub protocol
- Connection conn=DriverManager.getConnection(url,"username","password");
It doesn't need to be written like this DriverManager.registerDriver(new com.mysql.jdbc.Driver()), as a result of com.mysql.jdbc.Driver Class static code, which has been registered
static {
try {
java.sql.DriverManager.registerDriver(new Driver());
} catch (SQLException E) {
throw new RuntimeException("Can't register driver!");
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
from new com.mysql.jdbc.Driver() You can know , Here you need to create an instance of the class . To create an instance of a class, you need to java The class is passed in the file import Import , Otherwise you will report an error . namely : In this way , The program cannot be separated from the driver class package when compiling , It brings trouble for the program to switch to other databases
3.System.setProperty("jdbc.drivers","com.mysql.jdbc.Driver");
- System.setProperty("jdbc.driver","com.mysql.jdbc.Driver"); // System properties specify the database driver
- String url="jdbc:mysql://localhost:3306/databasename"; // Database connection sub protocol
- Connection conn=DriverManager.getConnection(url,"username","password");
You can import more than one at the same time jdbc drive , Use a colon in the middle “:” Separate , such as System.setProperty("jdbc.drivers","XXXDriver:XXXDriver:XXXDriver"); In this way, three database drivers are registered at one time .
边栏推荐
- Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
- Introduction et prévention des essais de pénétration
- Data insertion in C language
- Following nym, the new project Galaxy token announced by coinlist is gal
- Translation d30 (with AC code POJ 28:sum number)
- Project practice, redis cluster technology learning (11)
- Sil/pil test of matlab code generation
- [200 Shengxin literatures] 96 joint biomarkers of immune checkpoint inhibitor response in advanced solid tumors
- [unreal] key to open the door blueprint notes
- [ue5] animation redirection: how to import magic tower characters into the game
猜你喜欢
2837xd代码生成模块学习(2)——ADC、ePWM模块、Timer0
Leetcode -- the nearest common ancestor of 236 binary tree
Alibaba cloud SMS service
2837xd code generation - stateflow (3)
UE4 night lighting notes
Alibaba cloud SLS log service
The primary market project galaxy will conduct public offering on coinlist on February 17
2.14 is it Valentine's day or Valentine's day when the mainstream market continues to fluctuate and wait for changes?
【虚幻】过场动画笔记
Ue5 - ai Pursuit (Blueprint, Behavior tree)
随机推荐
Tools used for Yolo object recognition and data generation
Career planning and development
2837xd代码生成模块学习(2)——ADC、ePWM模块、Timer0
Leetcode -- the nearest common ancestor of 236 binary tree
Junit4运行mvn test 测试套件升级方案
2837xd 代码生成——StateFlow(2)
阿里云SLS日志服务
[unreal] key to open the door blueprint notes
Configuration programmée du générateur de plantes du moteur illusoire UE - - Comment générer rapidement une grande forêt
QT qlabel style settings
Blender模型导入ue、碰撞设置
Ctrip starts mixed office. How can small and medium-sized enterprises achieve mixed office?
[illusory] weapon slot: pick up weapons
The road is blocked and long, and the line is coming
Junit5 supports suite methods
[ue5] blueprint making simple mine tutorial
C language strawberry
2837xd 代码生成——补充(2)
Memories of a chat
How much is it to develop a system software in Beijing, and what funds are needed to develop the software