SpringBoot通过yml文件连接MySQL遇到的问题 - Go语言中文社区

SpringBoot通过yml文件连接MySQL遇到的问题



问题1

之前都是通过XML文件连接MySQL和其他相关的配置的,然后发现yml这种方式比较方便又简洁,不过要小心空格问题。在配置MySQL的连接信息后,启动项目后总是报错:
在这里插入图片描述
这是我的配置方式:

spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    username: root
    password: !1234
    url:  jdbc:mysql://localhost:3306/premission?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true

解决

当我将连接密码设置成全英文的时候发现可以正常启动的~但上面这种却不行,百度了一下,有人也遇到过这种问题,不过他是全数字的,然后说用单引号将密码括起来,依葫芦画瓢,我也用单引号括起来,然后就可以了。

问题2

The server time zone value 'XXXXXX' 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 util。这是控制台报的第二个错误,好像是数据库的时区设置有问题(话说我以前也连的好好的,怎么就有这种错误呢,难道是因为yml文件连接就会产生这种问题?有点扯淡…)

解决

在这里插入图片描述

问题3

吐槽:有、烦~

java.sql.SQLException: Unknown system variable 'query_cache_size'
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:545)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:513)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:115)
at com.mysql.cj.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:1983)
at com.mysql.cj.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:1936)
at com.mysql.cj.jdbc.StatementImpl.executeQuery(StatementImpl.java:1422)
at com.mysql.cj.jdbc.ConnectionImpl.loadServerVariables(ConnectionImpl.java:2831)
at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:2381)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:1739)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:1596)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:633)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:347)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:219)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:270)

解决

说是连接MySQL的驱动的版本不一致的问题我的mysql是8.0的,在maven中,将我的连接驱动改成8.0版本
在这里插入图片描述


版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/legendaryhaha/article/details/95487525
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢