IDEA 自动提示配置数据库连接属性的坑
application.yml 中的数据库连接配置如下
# 应用名称
spring:
application:
name: spring-data-jpa
# 数据库配置
datasource:
url: jdbc:mysql://192.168.32.32:3306/teach?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
data-username: root #data-username 是使用idea 自动提示的属性名
data-password: 123456 #data-password 是使用idea 自动提示的属性名
driver-class-name: com.mysql.cj.jdbc.Driver
这样会导致程序连接数据库时,报如下错误
java.sql.SQLException: Access denied for user ‘‘@‘192.168.44.177‘ (using password: NO) #这里是自己本机的IP地址,很奇怪,明明自己上面是配置的服务器的IP
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) ~[mysql-connector-java-8.0.22.jar:8.0.22]
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.22.jar:8.0.22]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.22.jar:8.0.22]
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836) ~[mysql-connector-java-8.0.22.jar:8.0.22]
解决方案:
# 应用名称
spring:
application:
name: spring-data-jpa
# 数据库配置
datasource:
url: jdbc:mysql://192.168.32.32:3306/teach?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
username: root #正确的连接属性-用户名
password: 123456 #正确的连接属性-密码
driver-class-name: com.mysql.cj.jdbc.Driver