Manage database accounts and permissions
Data Management (DMS) lets you create database accounts for MySQL, MongoDB, and PostgreSQL databases, customize combinations of permission types, and grant table-level permissions. This topic describes how to create, edit, and delete database accounts and manage account permissions in DMS.
DMS supports account management only for MySQL, PostgreSQL, and MongoDB databases. To manage accounts of other database engines, go to the console of the corresponding service.
Prerequisites
The database is one of the following types:
MySQL: ApsaraDB RDS for MySQL, PolarDB for MySQL, AnalyticDB for MySQL, a self-managed MySQL database, a self-managed MariaDB database, or ApsaraDB for MariaDB.
ApsaraDB for MongoDB.
NoteIf you create a user in the Admin database, make sure that at least one existing user has the permission to create users, such as dbAdminAnyDatabase, userAdmin, or userAdminAnyDatabase.
PostgreSQL: ApsaraDB RDS for PostgreSQL or AnalyticDB for PostgreSQL.
Your system role is DMS administrator, DBA, or regular user (instance owner). For more information, see System roles.
The Database account and Database password of the target database are obtained.
If you want to create accounts in the DMS console, make sure that the Database account used to log on to DMS has the permission to create users.
Examples of account permission management
Grant account A the global
SELECTandUPDATEpermissions.NoteGlobal permissions apply at the database instance level. For more information about global permission types, see Permission reference.
Grant account B the
SELECTpermission on a single table or theUPDATEpermission on a specific column.NoteObject permissions can apply to all database objects or to one or more specified database objects. For more information about object permission types, see Permission reference.
Manage database accounts
Create a database account
Database accounts created through DMS are standard accounts.
A DMS administrator is a RAM user that manages access to the DMS console and approves operations. A privileged database account is defined at the database instance level and has database operation permissions such as CREATE USER and GRANT. The two belong to different permission systems: to run database administration operations such as CREATE USER in DMS, you must use a privileged database account. A DMS administrator does not have these database-level permissions.
If you encounter the following error when you run CREATE USER in DMS:
execute create_user failed: you need (at least one of) the create user privilege for this operationTroubleshoot the issue as follows:
Create a privileged account in the ApsaraDB RDS console, log on to DMS with that account, and then retry the operation.
Alternatively, create the database user directly on the Account Management page of the ApsaraDB RDS console.
If the DMS instance has security hosting mode enabled, you may not be able to switch the database account in DMS. In this case, create the account in the ApsaraDB RDS console, or adjust the security hosting settings of the instance before you retry.
Create a MySQL database account
Log in to DMS 5.0.
-
Log on to the destination database. For more information, see Log on to a database.
-
On the home page, click the database instance in the navigation pane on the left. In the instance list, right-click the destination instance name and click Database Account Management.
-
On the Database Account Management page, click Create Database Account in the upper-left corner.
In the dialog box that appears, configure the following parameters.
Click the Basic settings tab and configure the parameters.
Parameter
Description
Database account
The name of the account used to log on to the database.
Host
The IP address from which the account is allowed to access the database.
NoteIf you leave this parameter empty, the account is not restricted to a specific IP address. The default value is
%.Password
The logon password.
Confirm Password
Enter the logon password again.
NoteThe SQL statement generated from the preceding parameters is in the following format:
CREATE USER `username`@`host` IDENTIFIED BY `password`;.To configure Advanced Options, click the Advanced Options button and configure the options.
For example, the SQL statement generated from the following settings is:
GRANT USAGE ON *.* TO 'username'@'host' WITH MAX_QUERIES_PER_HOUR 100 MAX_UPDATES_PER_HOUR 200 MAX_CONNECTIONS_PER_HOUR 300 MAX_USER_CONNECTIONS 400;Click the Global permissions tab and select the target permissions. For more information about global permissions, see MySQL global permissions.
NoteIf you use a standard account and cannot find the target permission in the permission type list, the account may not have the required permission or the instance type may not support the permission. If the issue is caused by insufficient account permissions, retry with a privileged account.
Click the Object permissions tab and configure the parameters. For more information about object permissions, see MySQL object permissions.
For example, the SQL statements generated from the following settings are:
GRANT SELECT,INSERT ON `rds_db`.* TO 'username'@'host'; GRANT DELETE ON `rds_db`.`rds_table` TO 'username'@'host';
Click Confirm.
In the Preview SQL Statement dialog box, click Confirm.
NoteDatabase instances in Security Collaboration mode are restricted by security rules. If the operation cannot be performed, follow the on-screen instructions or contact a DBA or DMS administrator. For more information about how to adjust security rules, see FAQ.
Create a MongoDB database account
Log in to DMS 5.0.
Log on to the target database. For more information, see Log on to a database.
ImportantFor a MongoDB replica set instance, log on to the primary node.
-
On the home page, click the database instance in the navigation pane on the left. In the instance list, right-click the destination instance name and click Database Account Management.
Click Create User in the upper-left corner of the page and configure the following information.
Configure the user information.
In the Create User dialog box, the Current Database Permissions tab provides the following roles for you to select:
Normal operation role:
read(permission to query data in the current database) andreadWrite(permission to insert, delete, modify, and query data in the current database)Administrator operation role:
dbAdmin(management operations on database objects, without read and write permission on the database) anduserAdmin(permission to create users in the current database)
Parameter
Description
Target database
Select the database to which the user belongs from the drop-down list.
NoteIf you select a database other than admin, the created user is a standard user.
If you select the admin database, the created user is a privileged user.
Username
The name of the user.
Chinese characters are not supported.
Letters, digits, and special characters are supported.
Special characters include:
!#$%^&*()_+-=
Password
The password of the user.
To ensure data security, the password must be 8 to 32 characters in length and contain at least three of the following character types:
Uppercase letters
Lowercase letters
Digits
Special characters (
!#$%^&*()_+-=)
Confirm Password
Enter the password again.
Configure the permissions of the user.
NoteIf you select the admin database as the target database:
On the Current Database Permissions tab, you can configure permissions such as Normal operation role, Administrator operation role, Instance-level operation role, Cluster management role, Backup and restore role, and Superuser role. For more information about role permissions, see MongoDB role permissions.
You can also click the Other Database Permissions tab to add database names and configure role permissions for the corresponding databases.
If you select a database other than admin as the target database:
On the Current Database Permissions tab, you can configure only the Normal operation role and Administrator operation role for the current database. For more information about role permissions, see MongoDB role permissions.
The Other Database Permissions tab is not available.
Click Confirm.
NoteDatabase instances in Security Collaboration mode are restricted by security rules. If the operation cannot be performed, follow the on-screen instructions or contact a DBA or DMS administrator.
Create a PostgreSQL database account
Log in to DMS 5.0.
Log on to the target database. For more information, see Log on to a database.
Click Database instances on the left side of the homepage. In the instance list, right-click the target instance name and click Account Management.
On the Account Management page, click Create User in the upper-left corner.
In the dialog box that appears, configure the following parameters.
Click the Basic settings tab and configure the parameters.
Parameter
Description
User name
The username of the account.
Password
The logon password.
Confirm Password
Enter the logon password again.
Password expiration time
The expiration time of the password. For example, if you set the password to expire at 00:00 on December 30, 2021, the password becomes invalid at that time.
This parameter is optional. By default, the password does not expire.
Connection limit
The maximum number of concurrent connections for the account. For example, if you set this parameter to 10, the account can connect to the database from up to 10 clients at the same time.
The default value is -1, which indicates that the number of connections is not limited.
Remarks
The description of the account.
Click the Permissions tab and select the target permissions.
Permission type
Description
Allow logon
The logon permission. The corresponding SQL commands are
LOGINandNOLOGIN. By default, logon is allowed.Allow user creation
The permission to create database accounts. The corresponding SQL commands are
CREATEROLEandNOCREATEROLE. By default, user creation is allowed.Allow database creation
The permission to create databases. The corresponding SQL commands are
CREATEDBandNOCREATEDB. By default, database creation is allowed.
Click Confirm.
In the Preview SQL dialog box, click Confirm.
NoteDatabase instances in Security Collaboration mode are restricted by security rules. If the operation cannot be performed, follow the on-screen instructions or contact a DBA or DMS administrator. For more information about how to adjust security rules, see Permission reference.
Edit or delete an account
You can use the account editing feature to modify the Username, Password, and MySQL Global permissions and Object permissions of an account.
Log in to DMS 5.0.
Click Database instances on the right side of the homepage. In the instance list, right-click the target instance name and click Account Management.
Find the target account and click Edit or Delete to perform the corresponding operation.
Edit or delete an account
You can use the account editing feature to modify the Username, Password, and MySQL Global permissions and Object permissions of an account.
Log in to DMS 5.0.
-
On the home page, click the database instance in the navigation pane on the left. In the instance list, right-click the destination instance name and click Database Account Management.
Find the target account and click Edit or Delete to perform the corresponding operation.
Switch the database account
Log in to DMS 5.0.
In the Database instances area on the left, find the target instance.
Right-click the instance name and select Edit Instance.
In the Basic Information section, enter the database account and password that you want to use for logon.
Click Save.
Grant or revoke database account permissions
Log in to DMS 5.0.
-
On the home page, click the database instance in the navigation pane on the left. In the instance list, right-click the destination instance name and click Database Account Management.
Find the target account and click Edit.
In the permissions area, select the target permissions to grant them or clear the target permissions to revoke them, and then click Confirm.
Permission reference
MySQL global permissions
MySQL object permissions
MongoDB role permissions
Related topics
Best practices for permission management in ApsaraDB RDS for PostgreSQL
FAQ
Q: When I create a permission user, an error indicates that the CREATE_USER command is blocked by security rules. How do I resolve this issue?
A: Resolve this issue by following the steps in the error dialog box. Perform the following operations:
View the name of the security rule set bound to the instance.
In the instance list on the left side of the console homepage, find the target instance, right-click it, and click View Details.
Adjust the security rules.
-
Log on to DMS.
-
In the top menu bar, choose .
-
On the security rules tab, find the target rule set and click Edit in the Actions column.
-
In the left-side navigation pane, click SQL Correct.
Set Checkpoint to SQL execution rules.
Find the Allow all DCL statements to be executed directly in SQL Console security rule, and click Edit in the Actions column.
In the Rule DSL section of the Edit Rule dialog box, change the rule to:
if @fac.sql_type in ["DCL"] then @act.allow_execute_direct end.This syntax matches the entire DCL category and covers all DCL statements such as
CREATE USERandGRANT, without listing each SQL type individually. In this rule,allow_execute_directallows statements to be executed directly in SQL Console, whereasallow_submitonly allows statements to be submitted as tickets for approval. The two options differ in how permissive they are, so choose based on your requirements.
-
Click Submit.
Check the risk identification rules. Under SQL Change > Risk Identification Rules, verify whether a rule flags DCL statements as high risk. If such a rule exists, disable or adjust it. Otherwise, it overrides the DCL rule you configured in the previous step, and the rule change does not take effect.
Only instances in Security Collaboration mode support editing security rules. Instances in Flexible Management and Stable Change modes use built-in system rules that cannot be edited. If the target instance is not in Security Collaboration mode, purchase a Security Collaboration license and switch the control mode before you modify the rules as described above. Also make sure that the rule set you modified is associated with the target instance. Otherwise, the changes do not take effect.