Managing databases in Managed Service for MySQL®
You can add and remove databases, view information about them, and manage some database settings using Managed Service for MySQL® interfaces.
Warning
You can't manage databases using SQL commands. However, you can perform the ALTER DATABASE operation.
Getting a list of cluster databases
- Navigate to the folder dashboard
and select Managed Service for MySQL. - Click the name of the cluster you need and select the Databases tab.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
To get a list of databases in a cluster, run the command:
yc managed-mysql database list \
--cluster-name=<cluster_name>
You can request the cluster name with the list of clusters in the folder.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>" -
Use the Database.list method and make a request, e.g., via cURL
:curl \ --request GET \ --header "Authorization: Bearer $IAM_TOKEN" \ --url 'https://mdb.api.cloud.yandex.net/managed-mysql/v1/clusters/<cluster_ID>/databases'You can request the cluster ID with the list of clusters in the folder.
-
View the server response to make sure the request was successful.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume the repository contents are stored in the
~/cloudapi/directory. -
Use the DatabaseService/List call and make a request, e.g., via gRPCurl
:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/mysql/v1/database_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>" }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.mysql.v1.DatabaseService.ListYou can request the cluster ID with the list of clusters in the folder.
-
View the server response to make sure the request was successful.
Creating a database
Note
You can create a maximum of 1000 databases in each cluster.
-
Navigate to the folder dashboard
and select Managed Service for MySQL. -
Click the cluster name.
-
If the new database does not have an owner among its current users, add such a user.
-
Select the Databases tab.
-
Click Create database.
-
Enter the database name and click Create.
The DB name may contain Latin letters, numbers, hyphens, and underscores. The name may be up to 63 characters long. Such names as
mysql,sys,information_schema, andperformance_schemaare reserved for Managed Service for MySQL®. You cannot create DBs with these names. -
Grant privileges for access to the database created to the appropriate cluster users.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
To create a database in a cluster:
-
View a description of the CLI create database command:
yc managed-mysql database create --help -
Run the create database command:
yc managed-mysql database create <DB_name> --cluster-name=<cluster_name>The DB name may contain Latin letters, numbers, hyphens, and underscores. The name may be up to 63 characters long. Such names as
mysql,sys,information_schema, andperformance_schemaare reserved for Managed Service for MySQL®. You cannot create DBs with these names.You can request the cluster name with the list of clusters in the folder.
Managed Service for MySQL® runs the create database operation.
-
Open the current Terraform configuration file that defines your infrastructure.
For more information about creating this file, see Creating clusters.
-
Add the
yandex_mdb_mysql_databaseresource:resource "yandex_mdb_mysql_database" "<DB_name>" { cluster_id = "<cluster_ID>" name = "<DB_name>" }The DB name may contain Latin letters, numbers, hyphens, and underscores. The name may be up to 63 characters long. Such names as
mysql,sys,information_schema, andperformance_schemaare reserved for Managed Service for MySQL®. You cannot create DBs with these names. -
Make sure the settings are correct.
-
In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
-
Run this command:
terraform validateTerraform will show any errors found in your configuration files.
-
-
Confirm updating the resources.
-
Run this command to view the planned changes:
terraform planIf you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply -
Confirm updating the resources.
-
Wait for the operation to complete.
-
-
For more information, see the Terraform provider documentation.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>" -
Use the Database.create method and make a request, e.g., via cURL
:curl \ --request POST \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-mysql/v1/clusters/<cluster_ID>/databases' \ --data '{ "databaseSpec": { "name": "<DB_name>" } }'The DB name may contain Latin letters, numbers, hyphens, and underscores. The name may be up to 63 characters long. Such names as
mysql,sys,information_schema, andperformance_schemaare reserved for Managed Service for MySQL®. You cannot create DBs with these names.You can request the cluster ID with the list of clusters in the folder.
-
View the server response to make sure the request was successful.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume the repository contents are stored in the
~/cloudapi/directory. -
Use the DatabaseService/Create call and make a request, e.g., via gRPCurl
:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/mysql/v1/database_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>", "database_spec": { "name": "<DB_name>" } }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.mysql.v1.DatabaseService.CreateThe DB name may contain Latin letters, numbers, hyphens, and underscores. The name may be up to 63 characters long. Such names as
mysql,sys,information_schema, andperformance_schemaare reserved for Managed Service for MySQL®. You cannot create DBs with these names.You can request the cluster ID with the list of clusters in the folder.
-
View the server response to make sure the request was successful.
Deleting a database
- Navigate to the folder dashboard
and select Managed Service for MySQL. - Click the cluster name and open the Databases tab.
- Click
in the row with the DB and select Delete.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
To delete a database, run the command:
yc managed-mysql database delete <DB_name> --cluster-name=<cluster_name>
You can request the cluster name with the list of clusters in the folder.
-
Open the current Terraform configuration file that defines your infrastructure.
For more information about creating this file, see Creating clusters.
-
Delete the
yandex_mdb_mysql_databaseresource with the name of the database you want to delete. -
Make sure the settings are correct.
-
In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
-
Run this command:
terraform validateTerraform will show any errors found in your configuration files.
-
-
Confirm updating the resources.
-
Run this command to view the planned changes:
terraform planIf you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply -
Confirm updating the resources.
-
Wait for the operation to complete.
-
-
For more information, see the Terraform provider documentation.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>" -
Use the Database.delete method and make a request, e.g., via cURL
:curl \ --request DELETE \ --header "Authorization: Bearer $IAM_TOKEN" \ --url 'https://mdb.api.cloud.yandex.net/managed-mysql/v1/clusters/<cluster_ID>/databases/<DB_name>'You can request the cluster ID with the list of clusters in the folder, and the DB name, with the list of DBs in the cluster.
-
View the server response to make sure the request was successful.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume the repository contents are stored in the
~/cloudapi/directory. -
Use the DatabaseService/Delete call and make a request, e.g., via gRPCurl
:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/mysql/v1/database_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>", "database_name": "<DB_name>" }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.mysql.v1.DatabaseService.DeleteYou can request the cluster ID with the list of clusters in the folder, and the DB name, with the list of DBs in the cluster.
-
View the server response to make sure the request was successful.
Warning
Before creating a new database with the same name, wait for the delete operation to complete, otherwise the database being deleted will be restored. Operation status can be obtained with a list of cluster operations.
Setting SQL mode
You can set or change the value of the sql_mode setting that defines the SQL mode for the database. This operation restarts the cluster hosts.
- Navigate to the folder dashboard
and select Managed Service for MySQL. - Select the cluster and click Edit in the top panel.
- Under DBMS settings, click Settings.
- In the list of the settings, locate the sql_mode parameter.
- Configure a set of SQL modes in the drop-down list. To restore default settings, click Reset.
- Click Save in the DBMS settings dialog box.
- Click Save changes.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
Set the SQL modes in the --set parameter, e.g.:
yc managed-mysql cluster update-config \
--name <cluster_name> \
--set '"sql_mode=NO_KEY_OPTIONS,NO_TABLE_OPTIONS"'
Pay close attention to quotation marks: the entire string must constitute the parameter value, including sql_mode=.
You can request the cluster name with the list of clusters in the folder.
-
Open the current Terraform configuration file that defines your infrastructure.
For more information about creating this file, see Creating clusters.
-
Set the SQL modes in the
sql_modeparameter undermysql_config, e.g.:resource "yandex_mdb_mysql_cluster" "<cluster_name>" { ... mysql_config = { sql_mode = "<SQL_mode_list>" ... } } -
Make sure the settings are correct.
-
In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
-
Run this command:
terraform validateTerraform will show any errors found in your configuration files.
-
-
Confirm updating the resources.
-
Run this command to view the planned changes:
terraform planIf you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply -
Confirm updating the resources.
-
Wait for the operation to complete.
-
-
For more information, see the Terraform provider documentation.
Time limits
A Terraform provider sets the timeout for Managed Service for MySQL® cluster operations:
- Creating a cluster, including by restoring one from a backup: 15 minutes.
- Editing a cluster, including the MySQL® version update: 60 minutes.
- Deleting a cluster: 15 minutes.
Operations exceeding the set timeout are interrupted.
How do I change these limits?
Add the timeouts block to the cluster description, for example:
resource "yandex_mdb_mysql_cluster" "<cluster_name>" {
...
timeouts {
create = "1h30m" # 1 hour 30 minutes
update = "2h" # 2 hours
delete = "30m" # 30 minutes
}
}
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>" -
Use the Cluster.update method and send the following request, e.g., via cURL
:Warning
The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the
updateMaskparameter as a single comma-separated string.curl \ --request PATCH \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-mysql/v1/clusters/<cluster_ID>' \ --data '{ "updateMask": "configSpec.mysqlConfig_<MySQL®_version>", "configSpec": { "mysqlConfig_<MySQL®_version>": { "sqlMode": [ "<SQL_mode_1>", "<SQL_mode_2>", ..., "<SQL_mode_N>" ] } } }'Where:
-
updateMask: List of parameters to update as a single string, separated by commas.Only one parameter is provided in this case.
-
configSpec.mysqlConfig_<MySQL®_version>.sqlMode: List of SQL modes. For available modes, see the MySQL® documentation:
You can request the cluster ID with the list of clusters in the folder.
-
-
View the server response to make sure the request was successful.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume the repository contents are stored in the
~/cloudapi/directory. -
Use the ClusterService/Update call and send the following request, e.g., via gRPCurl
:Warning
The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the
update_maskparameter as an array ofpaths[]strings.Format for listing settings
"update_mask": { "paths": [ "<setting_1>", "<setting_2>", ... "<setting_N>" ] }grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/mysql/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>", "update_mask": { "paths": [ "config_spec.mysql_config_<MySQL®_version>" ] }, "config_spec": { "mysql_config_<MySQL®_version>": { "sql_mode": [ "<SQL_mode_1>", "<SQL_mode_2>", ..., "<SQL_mode_N>" ] } } }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.mysql.v1.ClusterService.UpdateWhere:
-
update_mask: List of parameters to update as an array ofpaths[]strings.Only one parameter is provided in this case.
-
config_spec.mysql_config_<MySQL®_version>.sql_mode: List of SQL modes. For available modes, see the MySQL® documentation:
You can request the cluster ID with the list of clusters in the folder.
-
-
View the server response to make sure the request was successful.
Changing a character set and collation rules
To configure the CHARACTER SET and COLLATE database settings:
-
Connect to the database under the account of the database owner or as a user with the
ALTERprivilege for this database. -
Run the ALTER DATABASE
query:ALTER DATABASE <DB_name> CHARACTER SET = 'utf8mb4' COLLATE = 'utf8mb4_unicode_ci'; -
To apply settings to the database tables along with the database, convert the tables with the same settings:
ALTER TABLE <DB_name>.<table_name> CONVERT TO CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_unicode_ci';