Java 我的 H2 数据库文件在哪里?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6397716/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 05:35:11  来源:igfitidea点击:

Where are my H2 database files?

javah2

提问by Konrad Garus

I'm just evaluating the H2 database... I downloaded and unpacked the installation and connect to a database at jdbc:h2:file:/home/konrad/test. /home/konradis my home dir, testdoes not exist (I expect H2 to create it).

我只是在评估 H2 数据库...我下载并解压缩安装并连接到jdbc:h2:file:/home/konrad/test. /home/konrad是我的家目录,test不存在(我希望 H2 创建它)。

The console seems to work OK. I created a table and inserted a row to it. Even if I disconnect and reconnect the console, I can see and query the table.

控制台似乎工作正常。我创建了一个表并在其中插入了一行。即使我断开并重新连接控制台,我也可以查看和查询表。

However, I don't see the file I expected. Where is it?

但是,我没有看到我期望的文件。它在哪里?

采纳答案by Tomasz Nurkiewicz

Are you sure there is no:

你确定没有:

/home/konrad/test.h2.db

file? If not, try this:

文件?如果没有,试试这个:

$ lsof -p `jps -ml | grep h2 | cut -d' ' -f1` | grep \.h2\.db$

What it does is it look for Java process of H2 console, grabs its PID and lists all open files of that process, filtering by H2 database extension. Of course you can use PID of any other Java process accessing this DB. If it is persisted on the disk, you can't miss it.

它的作用是查找 H2 控制台的 Java 进程,获取其 PID 并列出该进程的所有打开文件,并按 H2 数据库扩展名进行过滤。当然,您可以使用访问此数据库的任何其他 Java 进程的 PID。如果它持久存在于磁盘上,您就不会错过它。

回答by Shiran Gabriel

Your database files can be found in your user directory. For windows

您的数据库文件可以在您的用户目录中找到。窗户用

C:\Users\<userName>

C:\Users\<userName>

Take a look at H2's FAQ, You can find more information here

查看 H2 的常见问题解答,您可以在此处找到更多信息

And in new versions of Spring, it's located simply in project root directory, like this :

在新版本的 Spring 中,它只是位于项目根目录中,如下所示:

spring boot db file location

spring boot db文件位置

And property is spring.datasource.url=jdbc:h2:file:./fileOrDbName

而财产是 spring.datasource.url=jdbc:h2:file:./fileOrDbName