how to create new database in H2?
Asked Answered
M

3

12

I have a site running locally on MySQL i want to run it on H2 database. I have just run h2.jar file for console on the browser but whenever I Log in I have seen the list jdbc:h2:/var/www/mysite/data/db; MODE=MySQL, information_schema and users.I can create tables in it but don't know how to create new database?

I am using Mode = MySQL type = H2 Database Engine in Embedded mode.

Manassas answered 23/6, 2014 at 18:33 Comment(0)
V
15

From http://www.h2database.com/html/tutorial.html#creating_new_databases,

By default, if the database specified in the URL does not yet exist, a new (empty) database is created automatically. The user that created the database automatically becomes the administrator of this database.

Vulgarian answered 23/6, 2014 at 18:36 Comment(1)
I have tried this and I want to name the database as mysite and more question i have SQL script for creating tables and inserting data. How can i run script or export it using H2 ?Manassas
D
3

The settings of the H2 Console are stored in a configuration file called .h2.server.properties in your user home directory. For Windows installations, the user home directory is usually C:\Documents and Settings\[username] or C:\Users\[username]. The configuration file contains the settings of the application and picked up when the H2 Console is started.

Below config to create a new database on startup:

  1. add newline in property file.

0=Generic H2 (Server)|org.h2.Driver|jdbc\:h2\:tcp\://localhost/~/db_name|sa

  1. open the command prompt go to the \bin directory where h2 has installed:

e.g. cd C:\Program Files (x86)\H2\bin

  1. and run following the command java -cp h2-1.4.194.jar org.h2.tools.Server.

Other General Settings:

webAllowOthers: allow other computers to connect.

webPort: the port of the H2 Console

webSSL: use encrypted TLS (HTTPS) connections.

Dogear answered 30/4, 2018 at 7:6 Comment(0)
W
0

in H2 schema is called as a database. created database using the command create or replace schema db_name

To verify whether database created or not using the command show databases;

Waxwing answered 22/6 at 3:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.