IDEA Access denied for user ''@'localhost' (using password: NO)一系列连贯问题

springboot使用jpa连接mysql一些列问题:

问题一:java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)

导致原因:根据智能提示选择了下面的配置书写格式

spring.datasource.data-username=root
spring.datasource.data-password=123456

 处理:正确的书写应该为

spring.datasource.username=root
spring.datasource.password=123456

问题二:You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

大意:您需要通过设置useSSL=false显式禁用SSL,或者设置useSSL=true并为服务器证书验证提供信任存储。

处理:在数据库连接追加 &verifyServerCertificate\=false&useSSL\=false

spring.datasource.url=jdbc\:mysql\://localhost\:3306/db01?useUnicode\=true&characterEncoding\=UTF-8&autoReconnect\=true&autoReconnectForPools\=true&zeroDateTimeBehavior\=convertToNull&verifyServerCertificate\=false&useSSL\=false

问题三:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'db01.hibernate_sequence' doesn't exist

参考:https://www.cnblogs.com/cdfive2018/p/9801362.html

背景:springboot 1.5.9.RELEASE 升级至 2.0.5.RELEASE时,spring-boot-starter-data-jpa使用了hibernate5

解决方法:spring.jpa.hibernate.use-new-id-generator-mappings=false 或 @GeneratedValue(strategy =GenerationType.IDENTITY)

验证:spring.jpa.hibernate.use-new-id-generator-mappings=false

问题消失====>出现新的问题:java.sql.SQLException: Field 'id' doesn't have a default value

原因是数据库主键没有设置自增:勾上自增继续验证

验证成功:

验证:@GeneratedValue(strategy =GenerationType.IDENTITY)

去掉:spring.jpa.hibernate.use-new-id-generator-mappings=false

此时:

问题复现:

修改为:

@GeneratedValue(strategy =GenerationType.IDENTITY)

验证:验证成功

说明两种方案皆可以。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值