All Products
Search
Document Center

PolarDB:CREATE DATABASE

Last Updated:Mar 28, 2026

CREATE DATABASE creates a logical database in PolarDB-X. Specify the default character set, collation, storage locality, and partitioning mode when creating the database.

Syntax

create_database_stmt:
    CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] database_name [database_option_list]

database_option_list:
    database_option [database_option ...]

database_option:
    [DEFAULT] {CHARACTER SET | CHARSET} [=] charset_name
  | [DEFAULT] COLLATE [=] collation_name
  | LOCALITY = locality_option}
  | [{PARTITION_MODE|MODE} = partition_mode_option]
  | [DEFAULT_SINGLE = default_single_option]

locality_option:
    'dn=storage_inst_id_list'

storage_inst_id_list:
    storage_inst_id[,storage_inst_id_list]

partition_mode_option:
     {'auto'|'partitioning'}
    |{'drds'|'sharding'}

default_single_option:
    {'on'|'off'}

Usage notes

  • Standard Edition instances do not support the DBPARTITION BY syntax used to create database shards and table shards.

  • Only Enterprise Edition instances support creating databases in DRDS mode.

Parameters

ParameterDescription
database_nameThe name of the database.
CHARSET charset_nameThe character set of the database.
COLLATE collation_nameThe collation of the database.
LOCALITYThe storage location of the database, specified as one or more data node (DN) IDs. The location cannot be changed after creation. If LOCALITY is not specified, PolarDB-X distributes data evenly across all storage nodes.
MODEThe partitioning mode of the logical database. Valid values: auto and drds. See Choose a partitioning mode for details. Default: drds.
DEFAULT_SINGLESpecifies whether to distribute single-table data across multiple DNs when no explicit partition definition is given. Valid only for AUTO mode databases. Available for PolarDB-X 5.4.17-16921956 or later. Valid values: on and off. Default: off.
Important

The partitioning mode (MODE) cannot be changed after the database is created.

Choose a partitioning mode

PolarDB-X supports two partitioning modes for logical databases. Choose the mode based on your table creation workflow.

AUTO modeDRDS mode
DefaultNoYes (default when MODE is not specified)
Table creation syntaxPARTITION BY HASH, PARTITION BY RANGE, PARTITION BY LISTDBPARTITION BY, TBPARTITION BY
Cross-node single tablesSupported (enable with DEFAULT_SINGLE='on')Not supported
Auto-partition by primary keySupported (enable with set global auto_partition=true)Not supported
Edition requirementNot restricted to Enterprise EditionEnterprise Edition only
ReferenceCREATE TABLE (AUTO mode)CREATE TABLE (DRDS mode)

For a detailed explanation of both modes, see Databases in AUTO mode and DRDS mode.

DEFAULT_SINGLE behavior in AUTO mode

DEFAULT_SINGLE controls what happens when you create a table in an AUTO mode database without specifying a partition definition.

DEFAULT_SINGLEBehavior
off (default)A single table is created.
onA single table is created and data is distributed across all data nodes in the instance. See Common table sharding.
Note

If both DEFAULT_SINGLE='on' and MODE='auto' are specified, DEFAULT_SINGLE='on' takes precedence, which disables automatic partitioning by primary key.

Examples

Create a database in AUTO mode with UTF-8

CREATE DATABASE test MODE=auto default CHARACTER SET UTF8;
Query OK, 1 row affected (0.00 sec)

Create a database on a specific storage node

Pin the database to a single storage node using LOCALITY. Table shards in the database are stored on the same node, isolating data by location.

CREATE DATABASE db1 MODE=drds LOCALITY='dn=polardbx-storage-0-master';

Verify the location after creation:

SHOW CREATE DATABASE db1 MODE=drds;
+----------+------------------------------------------------------------------------+
| DATABASE | CREATE DATABASE                                                        |
+----------+------------------------------------------------------------------------+
| db1      | CREATE DATABASE `db1` /* LOCALITY = "dn=polardbx-storage-0-master" */  |
+----------+------------------------------------------------------------------------+
1 row in set