Database management
You can add and remove databases, as well as view information about them.
There are two ways to manage cluster databases:
- Yandex.Cloud standard interfaces (CLI, API, or management console). Choose this method if you want to use all the features of the Yandex.Cloud managed service.
- SQL queries to the cluster. Choose this method if you want to use an existing solution for creating and managing databases, or if you need MySQL database support in Managed Service for ClickHouse.
Managing databases using SQL
To manage databases using SQL, create a cluster via the API with the sqlDatabaseManagement setting enabled. In this cluster:
- Databases can only be managed using SQL.
- Management using Yandex.Cloud standard interfaces (CLI, API, or management console) isn't possible.
- Users are managed under the
admin
account. The password for this account is set when creating a cluster.
To learn more about managing databases using SQL, see the documentation for ClickHouse.
Getting a list of cluster databases
- Go to the folder page and select Managed Service for ClickHouse.
- Click on the name of the cluster you need and select the Databases tab.
If you don't have the Yandex.Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To get a list of databases in a cluster, run the command:
$ yc managed-clickhouse database list
--cluster-name=<cluster name>
The cluster name can be requested with a list of folder clusters.
To get a list of cluster databases, use the list method.
-
Connect to the cluster using the admin account.
-
Get a list of databases:
SHOW DATABASES;
Creating a database
The number of databases in a cluster is unlimited.
- Go to the folder page and select Managed Service for ClickHouse.
- Click on the name of the cluster you need.
- Select the Databases tab.
- Click Add.
- Enter a name for the database and click Add.
Note
Database names may consist of Latin letters, numbers, dashes, and underscores. The maximum name length is 63 characters. You can't create a database named default
.
If you don't have the Yandex.Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
Run the create database command and set the name of the new database:
$ yc managed-clickhouse database create <database name>
--cluster-name <cluster name>
Managed Service for ClickHouse runs the create database operation.
Note
Database names may consist of Latin letters, numbers, dashes, and underscores. The maximum name length is 63 characters. You can't create a database named default
.
The cluster name can be requested with a list of folder clusters.
You can create a new database in a cluster using the create method.
-
Connect to the cluster using the admin account.
-
Create a database:
CREATE DATABASE <database name>;
To learn more about creating databases, see the documentation for ClickHouse.
Deleting a database
- Go to the folder page and select Managed Service for ClickHouse.
- Click on the name of the cluster you need and select the Databases tab.
- Click in the line of the necessary DB and select Delete.
If you don't have the Yandex.Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To delete a database, run the command:
$ yc managed-clickhouse database delete <database name>
--cluster-name=<cluster name>
The cluster name can be requested with a list of folder clusters.
You can delete a database using the delete method.
-
Connect to the cluster using the admin account.
-
Delete the database:
DROP DATABASE <database name>;
To learn more about deleting objects, see the documentation forClickHouse.
Warning
Before creating a new database with the same name, wait for the delete operation to complete, otherwise the database being deleted is restored. Operation status can be obtained with a list of cluster operations.