Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.5.5版本的h2数据库没有向后兼容,导致基于1.5.4的h2数据库去启动1.5.5会报错 #855

Open
AndyLvVip opened this issue Jun 28, 2023 · 1 comment
Labels
good first issue Good for newcomers

Comments

@AndyLvVip
Copy link

现象:1.5.5版本直接使用1.5.4的数据库时,报错:

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]

经调试发现

1.5.4版本的数据库,通过shell连接需要有默认用户名sa

java -cp .\h2-1.4.200.jar org.h2.tools.Shell -url "jdbc:h2:file:./h2/webasefront" -user "sa"

1.5.5版本的数据库是不需要默认用户名sa的

java -cp .\h2-1.4.200.jar org.h2.tools.Shell -url "jdbc:h2:file:./h2/webasefront"

目前解决方案:

基于1.5.4的数据库,不使用用户名创建一个数据库,然后通过以下数据迁移脚本迁移出不需要用户名的1.5.4的数据库,然后直接给1.5.5用,则1.5.5版本可以启动成功

// 将数据库导出脚本的命令:
SCRIPT TO 'backup.sql';

// 将脚本导入新数据库的命令:
RUNSCRIPT FROM 'backup.sql';

向后兼容性

如果1.5.5以及后面的版本要向后兼容,看是不是在application.yml的数据库用户名要配置上sa?

spring:
  datasource:
    url: jdbc:h2:file:../h2/webasefront;DB_CLOSE_ON_EXIT=FALSE
    databaseName: db
    driverClassName: org.h2.Driver
    serverName:
    username: sa
@CodingCattwo
Copy link
Contributor

感谢反馈!该issue将帮助到其他遇到h2数据库兼容问题的用户

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants