java.sql.SQLException: Access denied for user ''@'localhost' (using password: YES)

会飞的鱼 5月前 ⋅ 281 阅读

今天连接数据库老是报这个错误

java.sql.SQLException: Access denied for user ''@'localhost' (using password: YES)

 

查看properties文件后发现配置错误

spring.jpa.hibernate.ddl-auto=create
spring.datasource.url = jdbc:mysql://localhost:3306/test
spring.datasource.name=root
spring.datasource.password=root

正确的配置应该是这样的

spring.jpa.hibernate.ddl-auto=create
spring.datasource.url = jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=root

 

修改后又报这个错误

java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.

大概意思说需要时区支持,使用serverTimezone配置

需要在url后面加上?serverTimezone=GMT%2B8

具体代码如下:

spring.jpa.hibernate.ddl-auto=create
spring.datasource.url = jdbc:mysql://localhost:3306/jpa?serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=root

 


全部评论: 0

    我有话说: