当前位置:网站首页>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 .
边栏推荐
- Image recognition - Data Cleaning
- Centos7 one click compilation and installation of PHP script
- 渗透测试的介绍和防范
- 阿里云短信服务
- 2837xd 代碼生成——補充(1)
- Error reporting on the first day of work (incomplete awvs unloading)
- MySQL index
- High level application of SQL statements in MySQL database (II)
- VLAN experiment
- Basic notes of illusory AI blueprint (10000 words)
猜你喜欢

Blender摄像机环绕运动、动画渲染、视频合成

Following nym, the new project Galaxy token announced by coinlist is gal

【UE5】动画重定向:如何将幻塔人物导入进游戏玩耍

Tinyxml2 reading and modifying files

阿里云短信服务

UE illusory engine programmed plant generator setup -- how to quickly generate large forests

UE4 night lighting notes

UE5——AI追逐(蓝图、行为树)

This monitoring system makes workers tremble: turnover intention and fishing can be monitored. After the dispute, the product page has 404

Vs+qt set application icon
随机推荐
Junit4 runs MVN test test suite upgrade scheme
Ue5 - ai Pursuit (Blueprint, Behavior tree)
UE4 night lighting notes
Project practice, redis cluster technology learning (13)
Image recognition - data annotation
UE5——AI追逐(蓝图、行为树)
C language: making barrels
Junit5 支持suite的方法
2837xd 代码生成——补充(1)
Record the interesting process of using Xray for the first time
Project practice, redis cluster technology learning (VIII)
Blender模型导入ue、碰撞设置
In SQL injection, why must the ID of union joint query be equal to 0
It is the most difficult to teach AI to play iron fist frame by frame. Now arcade game lovers have something
虚幻AI蓝图基础笔记(万字整理)
[unreal] animation notes of the scene
虛幻AI藍圖基礎筆記(萬字整理)
[Yu Yue education] University Physics (Electromagnetics) reference materials of Taizhou College of science and technology, Nanjing University of Technology
Error reporting on the first day of work (error reporting when Nessus installs WinPcap)
Int to string, int to qstring