如何解决h2数据库和spring boot中的用户名和密码错误?
Posted
技术标签:
【中文标题】如何解决h2数据库和spring boot中的用户名和密码错误?【英文标题】:how to reslove wrong username and password error in h2 database and springboot? 【发布时间】:2020-05-28 12:14:55 【问题描述】:application.properties 中使用的属性
server.port=8085
spring.datasource.url=jdbc:h2:~/test spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.h2.console.enabled=true
spring.h2.console.path=/h2
错误 如何解决h2数据库和springboot中用户名密码错误?
org.h2.jdbc.JdbcSQLInvalidAuthorizationSpecException: Wrong user name or password [28000-200]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:461) ~[h2-1.4.200.jar:1.4.200]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:429) ~[h2-1.4.200.jar:1.4.200]
at org.h2.message.DbException.get(DbException.java:205) ~[h2-1.4.200.jar:1.4.200]
at org.h2.message.DbException.get(DbException.java:181) ~[h2-1.4.200.jar:1.4.200]
at org.h2.message.DbException.get(DbException.java:170) ~[h2-1.4.200.jar:1.4.200]
at org.h2.engine.Engine.validateUserAndPassword(Engine.java:357) ~[h2-1.4.200.jar:1.4.200]
at org.h2.engine.Engine.createSessionAndValidate(Engine.java:176) ~[h2-1.4.200.jar:1.4.200]
at org.h2.engine.Engine.createSession(Engine.java:166) ~[h2-1.4.200.jar:1.4.200]
at org.h2.engine.Engine.createSession(Engine.java:29) ~[h2-1.4.200.jar:1.4.200]
at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:340) ~[h2-1.4.200.jar:1.4.200]
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:173) ~[h2-1.4.200.jar:1.4.200]
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:152) ~[h2-1.4.200.jar:1.4.200]
at org.h2.Driver.connect(Driver.java:69) ~[h2-1.4.200.jar:1.4.200]
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-3.4.5.jar:na]
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:358) ~[HikariCP-3.4.5.jar:na]
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) ~[HikariCP-3.4.5.jar:na]
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:477) [HikariCP-3.4.5.jar:na]
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:560) [HikariCP-3.4.5.jar:na]
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) [HikariCP-3.4.5.jar:na]
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) [HikariCP-3.4.5.jar:na]
at org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration.lambda$h2Console$0(H2ConsoleAutoConfiguration.java:73) [spring-boot-autoconfigure-2.3.0.RELEASE.jar:2.3.0.RELEASE]
【问题讨论】:
->application.properties 文件:- server.port=8085 spring.datasource.url=jdbc:h2:~/test spring.datasource.driverClassName=org.h2.Driver spring.datasource.username =root spring.datasource.password=root spring.jpa.database-platform=org.hibernate.dialect.H2Dialect spring.jpa.show-sql=true spring.jpa.hibernate.ddl-auto=更新 spring.h2.console。 enabled=true spring.h2.console.path=/h2 【参考方案1】:尝试删除数据库文件(test.mv.db 和 test.trace.db)。 也许您之前已经创建过它并为它使用了不同的凭据。
【讨论】:
是否可以读取由其他用户创建的 H2 备份?假设我想更新我现有的 H2 DB 密码。我还能读取使用旧凭据创建的备份吗?【参考方案2】:Faced similar issue.
**Resolution (Worked for me)**:
[enter image description here][1]
1. Remove and re-add Saved Setting and Setting Name (highlighted screen enclosed)
[Generic H2(Embedded)]
2. Make sure JDBCURL, Username, Password match your application properties.
3. Update Build and restart Spring Boot Application.
另外,删除浏览器历史记录、缓存等,
**Sample Application. Properties**
spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:dcbapp
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
[1]: https://i.stack.imgur.com/r8YqY.jpg
【讨论】:
以上是关于如何解决h2数据库和spring boot中的用户名和密码错误?的主要内容,如果未能解决你的问题,请参考以下文章
如何在spring boot中创建H2+flyway测试数据库?