从yml中读取mysql配置,数据库已经存在,但还是出现数据库未找到的报错信息
问题描述:
yml文件
server:
port: 8080
spring:
datasource:
driveClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306//bank?useUnicode=true&CharacterEncoding=UTF-8&serverTimezone=utf&useSSL=false
username: root
password: 123456
jpa:
hibernate:
ddl-auto: none
show-sql: false
报错:
2021-07-30 05:57:10.685 ERROR 5280 --- [ main] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool.
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database '/hive'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_292]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_292]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_292]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_292]
答
哥,jdbc:mysql://localhost:3306//bank?useUnicode=true&CharacterEncoding=UTF-8&serverTimezone=utf&useSSL=false
你3306后面多打了个/,3306/bank才对
答
你连接的是bank这个数据库
Unknown database '/hive' 报错是没找到 hive 数据库
没连接对数据库吧
答
应该是配置文件的指定问题,项目是否是多模块的。是否是使用的第三方框架。
答
同时我注意可能是版本问题,检查了导入的jar包,是5.1.41,里面是没有jc目录的,我把这里修改之后,再测试还是不行
答
你用的是SpringBoot版本是多少?
SpringBoot 1.x 的可以试试这样写:
spring:
datasource:
driveClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/bank?useUnicode=true&CharacterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false
username: root
password: 123456
SpringBoot 2.x 的可以试试这样写:
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/bank?useUnicode=true&CharacterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false
username: root
password: 123456
答
同时 serverTimezone=utf 这里应该是utc 时区,而不是编码方式