I’m in the process of rebuilding one of my development boxes at the moment, and when I needed a SQL database engine this weekend to support a bit of quick prototyping, I decided I would take a shot at setting up a HyperSQL database server. This is something I’ve been meaning to look into for other reasons for a while: HyperSQL is small, fast, flexible, provides good SQL coverage (more complete, for instance than Apache Derby), and has the ability to tune its behavior to more closely mirror other SQL engines.
Here is a quick recipe for getting a basic server up and running. This should work equally well on both Mac OS X and Linux (I have used this basic recipe on both platforms).
My system already has a Java 7 JRE/JDK installed with the java command available in the shell’s PATH, which is really the only prerequisite. For the sake of simplicity, I install HyperSQL in /opt/hsqldb and I keep my database-related files in ~/hsqldb-catalogs/. Commands entered at the shell prompt are shown below starting with $, while commands entered in the HyperSQL CLI are shown below starting with >. Note that some of these commands may appear wrapped below; they should each be entered on a single line when used.
- Download the latest version of HyperSQL (version 2.3.1, as of this writing) from hsqldb.org.
- Unzip the downloaded file (assumed to be in ~/Downloads/):
$ cd ~/Downloads
$ unzip hsqldb-2.3.1.zip
$ sudo mv ./hsqldb-2.3.1/hsqldb /opt
$ rmdir hsqldb-2.3.1
- Create the folder where the server will store its database files:
$ mkdir ~/hsqldb-catalogs
- Create the properties file that provides basic information for the server, including our test database. Save this file as ~/hsqldb-catalogs/server.properties:
# File: server.properties
# HSQLDB configuration file
# Other configuration:
# Show stuff on the console (change this to true for production):
# Don't show JDBC trace messages on the console:
# Do not allow remote connections to create a database:
- Create the configuration file for the CLI HyperSQL tool, describing two different connections to our test database: one as the default system administrative user “SA” and one as a normal administrative user “RON” which we will create in a few minutes. Save this tool as ~/sqltool.rc:
# File: ~/sqltool.rc
# Connect to testdb on localhost as SA (no password initially):
# Connect to testdb on localhost as RON:
- Start the server. This will create our test database using the following commands in a terminal window:
$ cd ~/hsqldb-catalogs
$ sudo java -cp /opt/hsqldb/lib/hsqldb.jar org.hsqldb.server.Server --props ./server.properties
- Open a second terminal window and start the HyperSQL CLI “sqltool”, connecting to our test database as user “SA”:
$ java -jar /opt/hsqldb/lib/sqltool.jar localhost-sa
- As a general rule, I don’t like signing in using the system administrator account, so the first thing I typically do is create an administrative user account for my use:
> create user RON password 'strong-random-password';
> grant DBA to RON;
- Make sure you have your “strong-random-password” recorded correctly in ~/sqltool.rc, and restart the HyperSQL CLI:
$ java -jar /opt/hsqldb/lib/sqltool.jar localhost-ron
You’re done. You have a fully-functional database server, providing a single database called “testdb” for your use.
If you want to play with sample data, consider the following (while connected as either “SA” or your administrative account):
> create schema sampledata authorization DBA;
> set schema sampledata;
> \i /opt/hsqldb/sample/sampledata.sql
When you’re ready to shut down the server, you can do it while connected to the server as a user with DBA role:
Alternatively, you can shut down the server from the command-line:
$ java -jar /opt/hsqldb/lib/sqltool.jar --sql 'shutdown;' localhost-ron
Some final thoughts:
- Read the docs: the user guide and the utilities guide for HyperSQL are good, and provide thorough coverage of what HyperSQL is capable of (which appears to be quite a bit) and how to use it, including connecting via JDBC.
- You almost certainly want to set a password for the default “SA” user, and remember to update your ~/sqltool.rc file when you do.
- Protect ~/sqltool.rc — obviously this file, with information about catalogs, users, and passwords needs to be protected.