Outdated Version

You are viewing an older version of this section. View current production version.

CREATE DATABASE

Create a database.

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]...

Notes

  • db_name is the name to assign to this new MemSQL database.
  • WITH {SYNC | ASYNC} REPLICATION controls whether replication in high availability will be done synchronously or asynchronously. 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, refer to 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)