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 [WITH {SYNC | ASYNC} REPLICATION] [PARTITIONS n]
    [create_specification] ...

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 MemSQL database. Do not use the _XX suffix (such as test_db_01) while naming a MemSQL database as it may cause a mismatch with the database partition ordinals (sharded databases on each leaf node).
  • WITH {SYNC | ASYNC} REPLICATION controls whether replication in high availability will be done synchronously or asynchronously. The default mode is ASYNC. Partitions replicated synchronously will ensure commits have reached all replicas before acknowledging the transaction to the user client. While providing stronger consistency guarantees, this can negatively impact write performance. For more information, see Managing High Availability.
  • PARTITIONS n allows you to set the total number of partitions that the data will be split into. By default this is controlled by the default_partitions_per_leaf variable. Note that n refers to the total number of partitions across all leaves.
  • The CREATE DATABASE ... DEFAULT CHARSET= syntax is accepted by MemSQL for compatibility with MySQL, but it has no effect. MemSQL gives all databases a default charset of utf8.
  • This command must be run on the master aggregator node (see Node Requirements for MemSQL Commands).

Example

memsql> CREATE DATABASE IF NOT EXISTS test;
Query OK, 1 row affected (0.18 sec)