目录

springboot链接mysql错粗

目录

http://image.catbro.cn/bc1674bfaace4.png


  • 今天在使用spring boot 连接mysql数据库时报如下问题:

  • oading 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.

  • 因为我使用了当前最新的mysql-connector-java-8.0.9-rc.jar的MySQL驱动包,新的驱动包中com.mysql.jdbc.Driver'类已经过时,新的com.mysql.cj.jdbc.Driver’通过SPI自动注册,不再需要手动加载驱动类

  • Sat Apr 14 14:18:21 CST 2018 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.

  • 这也不是主要的:不建议在没有服务器身份验证的情况下建立SSL连接。根据MySQL 5.5.45+、5.6.26+和5.7.6+的要求,如果不设置显式选项,则必须建立默认的SSL连接。为了兼容不使用SSL的现有应用程序,verifyServerCertificate 属性被设置为“false”。您需要通过设置useSSL=false来显式禁用SSL,或者设置useSSL=true并为服务器证书验证提供信任存储。

      java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
      at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:127)
      at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95)
      at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:87)
      at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:61)
      at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:71)
      at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:76)
      at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:874)
      at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456)
      at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:234)
      at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:227)
      at java.sql.DriverManager.getConnection(DriverManager.java:664)
      at java.sql.DriverManager.getConnection(DriverManager.java:247)
      at com.mytestings.mysql.MySQLDemo.main(MySQLDemo.java:23)
      Caused by: com.mysql.cj.core.exceptions.InvalidConnectionAttributeException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
    
  • 就是上面第一句的SQL异常,我们需要在数据库 URL中设置serverTimezone属性:

      static final String DB_URL = "jdbc:mysql://localhost:3306/RUNOOB?serverTimezone=GMT%2B8";
    

-这里的 GMT%2B8 代表是东八区。