MySQL8.0 database connection errors and solutions
The use of outdated packages
- Error Messages
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
Cause Analysis
com.mysql.jdbc.Driver outdated, the new class is com.mysql.cj.jdbc.Driver
Solution
原代码 Class.forName("com.mysql.jdbc.Driver"); 修改后代码 Class.forName("com.mysql.cj.jdbc.Driver");
Above all built on the premise that the correct mysql-connector-java driver package (version to be consistent and MySQL version)
Inconsistent zone
- Error Messages
java.sql.SQLException: The server time zone value xxxxx is unrecognized or represents more than one time zone.
Cause Analysis
Inconsistent system time zone and time zone MySQL
Solution
a. Add the url serverTimezone items, such as
url="jdbc:mysql://localhost:3306/order_system?serverTimezone=GMT%2B8"(GMT%2B8表示gmt+8时区)
b.windos Under Settings
Modify "C: \ ProgramData \ MySQL \ MySQL Server 8.0 \ my.ini" file, add a line at the end of
default-time_zone='+8:00'
then
net stop mysqlxx#停止mysql服务 net start mysqlxx#开始MySQL服务,说实话这个命令不好使xx数字不是固定的,还要管理员运行 或者 右键我的电脑->管理->服务和应用程序->服务->右侧找到MySQL,点击->左侧点击重启动此服务
No SSL server connection acknowledgment
- Error Messages
CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended
Cause Analysis
No SSL server connection acknowledgment
Solution
a. In the url tail add? useSSL = false