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

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

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

IDEA Access denied for user ''@'localhost' (using password: NO)一系列连贯问题_第1张图片

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

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

IDEA Access denied for user ''@'localhost' (using password: NO)一系列连贯问题_第2张图片

参考: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

IDEA Access denied for user ''@'localhost' (using password: NO)一系列连贯问题_第3张图片

IDEA Access denied for user ''@'localhost' (using password: NO)一系列连贯问题_第4张图片

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

IDEA Access denied for user ''@'localhost' (using password: NO)一系列连贯问题_第5张图片

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

IDEA Access denied for user ''@'localhost' (using password: NO)一系列连贯问题_第6张图片

IDEA Access denied for user ''@'localhost' (using password: NO)一系列连贯问题_第7张图片

验证成功:

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

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

IDEA Access denied for user ''@'localhost' (using password: NO)一系列连贯问题_第8张图片

此时:

IDEA Access denied for user ''@'localhost' (using password: NO)一系列连贯问题_第9张图片

问题复现:

IDEA Access denied for user ''@'localhost' (using password: NO)一系列连贯问题_第10张图片

修改为:

@GeneratedValue(strategy =GenerationType.IDENTITY)

IDEA Access denied for user ''@'localhost' (using password: NO)一系列连贯问题_第11张图片

验证:验证成功

IDEA Access denied for user ''@'localhost' (using password: NO)一系列连贯问题_第12张图片

说明两种方案皆可以。

你可能感兴趣的:(springboot)