MySQL8.0连接数据库错误及解决方案

MySQL8.0连接数据库错误及解决方案

使用的包过时

  1. 错误信息

Loading class com.mysql.jdbc.Driver'. This is deprecated. The new driver class iscom.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary

  1. 原因分析

    com.mysql.jdbc.Driver已经过时,新的类是com.mysql.cj.jdbc.Driver

  2. 解决办法

    原代码
    Class.forName("com.mysql.jdbc.Driver");
    修改后代码
    Class.forName("com.mysql.cj.jdbc.Driver");
  3. 一切前提建立在正确的mysql-connector-java驱动包(版本要和MySQL版本一致)之上

    mysql-connector-java驱动包下载地址

时区不一致

  1. 错误信息

java.sql.SQLException: The server time zone value xxxxx is unrecognized or represents more than one time zone.

  1. 原因分析

    系统时区和MySQL时区不一致

  2. 解决办法

    a. 在url中添加serverTimezone项,如

    url="jdbc:mysql://localhost:3306/order_system?serverTimezone=GMT%2B8"(GMT%2B8表示gmt+8时区)

    b.windos下设置

    修改"C:\ProgramData\MySQL\MySQL Server 8.0\my.ini"文件,在末尾添加一行

    default-time_zone='+8:00'

    然后

    net stop mysqlxx#停止mysql服务
    net start mysqlxx#开始MySQL服务,说实话这个命令不好使xx数字不是固定的,还要管理员运行
    或者
    右键我的电脑->管理->服务和应用程序->服务->右侧找到MySQL,点击->左侧点击重启动此服务

SSL连接无服务器确认

  1. 错误信息

CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended

  1. 原因分析

    SSL连接无服务器确认

  2. 解决办法

    a. 在url尾部添加?useSSL=false

猜你喜欢

转载自www.cnblogs.com/redo19990701/p/11892430.html