H2
H2データベースの接続URL
2019-09-26
Database URL Overview - Features
table:url
Topic URL Format and Examples
Embedded (local) connection jdbc:h2:file:<path><databaseName>
jdbc:h2:~/test
jdbc:h2:file:/data/sample
jdbc:h2:file:C:/data/sample (Windows only)
In-memory (private) jdbc:h2:mem:
In-memory (named) jdbc:h2:mem:<databaseName>
jdbc:h2:mem:test_mem
Server mode (remote connections) using TCP/IP jdbc:h2:tcp://<server>:<port>/<path><databaseName>
jdbc:h2:tcp://localhost/~/test
jdbc:h2:tcp://dbserv:8084/~/sample
jdbc:h2:tcp://localhost/mem:test
Server mode (remote connections) using TLS jdbc:h2:ssl://<server>:<port>/<path><databaseName>
jdbc:h2:ssl://localhost:8085/~/sample;
Using encrypted files jdbc:h2:<url>;CIPHER=AES
jdbc:h2:ssl://localhost/~/test;CIPHER=AES
jdbc:h2:file:~/secure;CIPHER=AES
File locking methods jdbc:h2:<url>;FILE_LOCK={FILE|SOCKET|NO}
jdbc:h2:file:~/private;CIPHER=AES;FILE_LOCK=SOCKET
Only open if it already exists jdbc:h2:<url>;IFEXISTS=TRUE
jdbc:h2:file:~/sample;IFEXISTS=TRUE
Don't close the database when the VM exits jdbc:h2:<url>;DB_CLOSE_ON_EXIT=FALSE
Execute SQL on connection jdbc:h2:<url>;INIT=RUNSCRIPT FROM '~/create.sql'
jdbc:h2:file:~/sample;INIT=RUNSCRIPT FROM '~/create.sql'\;
RUNSCRIPT FROM '~/populate.sql'
User name and/or password jdbc:h2:<url>;USER=<username>;PASSWORD=<value>
jdbc:h2:file:~/sample;USER=sa;PASSWORD=123
Debug trace settings jdbc:h2:<url>;TRACE_LEVEL_FILE=<level 0..3>
jdbc:h2:file:~/sample;TRACE_LEVEL_FILE=3
Ignore unknown settings jdbc:h2:<url>;IGNORE_UNKNOWN_SETTINGS=TRUE
Custom file access mode jdbc:h2:<url>;ACCESS_MODE_DATA=rws
Database in a zip file jdbc:h2:zip:<zipFileName>!/<databaseName>
jdbc:h2:zip:~/db.zip!/test
Compatibility mode jdbc:h2:<url>;MODE=<databaseType>
jdbc:h2:~/test;MODE=MYSQL;DATABASE_TO_LOWER=TRUE
Auto-reconnect jdbc:h2:<url>;AUTO_RECONNECT=TRUE
jdbc:h2:tcp://localhost/~/test;AUTO_RECONNECT=TRUE
Automatic mixed mode jdbc:h2:<url>;AUTO_SERVER=TRUE
jdbc:h2:~/test;AUTO_SERVER=TRUE
Page size jdbc:h2:<url>;PAGE_SIZE=512
Changing other settings jdbc:h2:<url>;<setting>=<value>;<setting>=<value>...
jdbc:h2:file:~/sample;TRACE_LEVEL_SYSTEM_OUT=3
H2データベースの起動オプション
2019-04-26
$ java -cp lib/h2-1.4.199.jar org.h2.tools.Server -web -webAllowOthers -ifNotExists -webAdminPassword xxxxx
h2-1.4.199で存在しないデータベースにアクセスしたときに新しいデータベースが作られないという問題が発生した.
ifNotExists があると,存在しないデータベースにアクセスしたときに自動でデータベースが作られる.
webAdminPassword がないと管理者ツールにアクセスできないようになった.起動オプションに渡すのはうまくいかなかった..h2.server.propertiesに webAdminPassword=9999 のように書けば良い.
2020-06-04 -webAdminPasswordオプションが動いたなぜだ?
起動オプションの一覧
code:txt
java -cp lib/h2-1.4.199.jar org.h2.tools.Server -?
Starts the H2 Console (web-) server, TCP, and PG server.
Usage: java org.h2.tools.Server <options>
When running without options, -tcp, -web, -browser and -pg are started.
Options are case sensitive. Supported options are:
-help or -? Print the list of options
-web Start the web server with the H2 Console
-webAllowOthers Allow other computers to connect - see below
-webDaemon Use a daemon thread
-webPort <port> The port (default: 8082)
-webSSL Use encrypted (HTTPS) connections
-webAdminPassword Password of DB Console administrator
-browser Start a browser connecting to the web server
-tcp Start the TCP server
-tcpAllowOthers Allow other computers to connect - see below
-tcpDaemon Use a daemon thread
-tcpPort <port> The port (default: 9092)
-tcpSSL Use encrypted (SSL) connections
-tcpPassword <pwd> The password for shutting down a TCP server
-tcpShutdown "<url>" Stop the TCP server; example: tcp://localhost
-tcpShutdownForce Do not wait until all connections are closed
-pg Start the PG server
-pgAllowOthers Allow other computers to connect - see below
-pgDaemon Use a daemon thread
-pgPort <port> The port (default: 5435)
-properties "<dir>" Server properties (default: ~, disable: null)
-baseDir <dir> The base directory for H2 databases (all servers)
-ifExists Only existing databases may be opened (all servers)
-ifNotExists Databases are created when accessed
-trace Print additional trace information (all servers)
-key <from> <to> Allows to map a database name to another (all servers)
The options -xAllowOthers are potentially risky.
For details, see Advanced Topics / Protection against Remote Access.
See also http://h2database.com/javadoc/org/h2/tools/Server.html