Create a Database

This document describes how to create a database using SQL and various programming languages and lists the rules of database creation. In this document, the modatabase application is taken as an example to walk you through the steps of database creation.

Before you start

Before creating a database, do the following:

What is database

Database objects in MatrixOne contain tables, views and other objects.

Create databases

To create a database, you can use the CREATE DATABASE statement.

  1. CREATE DATABASE IF NOT EXISTS `modatabase`;

For more information on CREATE DATABASE statement, see CREATE DATABASE.

View databases

To view the databases in a cluster, use the SHOW DATABASES statement.

  1. SHOW DATABASES;

The following is an example output:

  1. +--------------------+
  2. | Database |
  3. +--------------------+
  4. | mo_catalog |
  5. | system |
  6. | system_metrics |
  7. | mysql |
  8. | information_schema |
  9. | modatabase |
  10. +--------------------+

Rules in database creation

  • Follow the Database Naming Conventions and name your database meaningfully.

  • You can create your own database using the CREATE DATABASE statement and change the current database using the USE {databasename}; statement in a SQL session.

  • Use the account user or user to create objects such as database, roles, and new users. Grant only the necessary privileges to roles and users. For more information, see Access control in MatrixOne.