Outdated Version
You are viewing an older version of this section. View current production version.
CREATE DATABASE
Creates a database.
Syntax
CREATE DATABASE [IF NOT EXISTS] db_name [sync_options] [PARTITIONS n]
[create_specification] ...
sync_options:
WITH {SYNC | ASYNC} DURABILITY
| WITH {SYNC | ASYNC} REPLICATION
| WITH {SYNC | ASYNC} DURABILITY {SYNC | ASYNC} REPLICATION
create_specification:
[DEFAULT] CHARACTER SET [=] charset_name
-- "schema" is an alias for "database"
CREATE SCHEMA [IF NOT EXISTS]...
Remarks
db_name
is the name to assign to this new SingleStore DB database. Do not use the_XX
suffix (such astest_db_01
) while naming a SingleStore DB database as it may cause a mismatch with the database partition ordinals (sharded databases on each leaf node).WITH {SYNC | ASYNC} REPLICATION
specifies whether high availability, redundancy-2 replication will be done synchronously or asynchronously. Synchronous replication from the master partitions will complete on all replicas before the commit of the transaction is acknowledged to the client application. IfWITH {SYNC | ASYNC} REPLICATION
is not specified, synchronous replication is used.WITH {SYNC | ASYNC} DURABILITY
specifies whether in-memory database updates you make using DDL and DML commands are also saved to the log on disk synchronously or asynchronously. Synchronous updates to the log on disk will complete before the commit of the transaction is acknowledged to the client application. IfWITH {SYNC | ASYNC} DURABILITY
is not specified, async durability is used.- You cannot specify WITH SYNC DURABILITY ASYNC REPLICATION.
PARTITIONS n
allows you to set the total number of partitions that the data will be split into. By default this is controlled by thedefault_partitions_per_leaf
variable. Note thatn
refers to the total number of partitions across all leaves.- The
CREATE DATABASE ... DEFAULT CHARSET=
syntax is accepted by SingleStore DB for compatibility with MySQL, but it has no effect. SingleStore DB gives all databases a default charset of utf8. - This command must be run on the master aggregator node (see Node Requirements for SingleStore DB Commands).
Examples
The following example creates a database that uses all of the default options.
CREATE DATABASE IF NOT EXISTS test;
Output:
Query OK, 1 row affected (0.18 sec)
The following example creates a database that uses sync durability and sync replication. The latter is enabled by default.
CREATE DATABASE IF NOT EXISTS test WITH SYNC DURABILITY;
Output:
Query OK, 1 row affected (3.71 sec)