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)
验证:验证成功
说明两种方案皆可以。