Help Center/ Data Replication Service/ FAQs/ Permissions Management/ Which MySQL Permissions Are Required for DRS?
Updated on 2023-07-03 GMT+08:00

Which MySQL Permissions Are Required for DRS?

DRS has certain permission requirements on accounts during migration, synchronization, and DR. This section describes the permission requirements on the MySQL engine.

Permission

  • You must have the login permission of the source and destination database connection accounts. If you do not have the account, perform the following operations to create one. user1 is used as an example.

    Reference statement: CREATE USER 'user1'@'host' IDENTIFIED BY 'password'

  • Table 1 lists the required permissions for real-time migration, synchronization, and DR.
    Table 1 Permission requirements and reference statements

    Function Modules

    Source/Service Database

    Destination/DR Database

    Real-time migration

    Full migration:

    SELECT, SHOW VIEW, and EVENT

    Reference statement: GRANT SELECT, SHOW VIEW, EVENT ON *.* TO 'user1';

    Full+incremental migration:

    SELECT, SHOW VIEW, EVENT, LOCK TABLES, REPLICATION SLAVE, and REPLICATION CLIENT

    • REPLICATION SLAVE and REPLICATION CLIENT are global permissions and must be enabled separately. The reference statement is as follows:

      GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'user1';

    • SELECT, SHOW VIEW, EVENT, and LOCK TABLES are non-global permissions. The reference statement is as follows:

      GRANT SELECT, SHOW VIEW, EVENT, LOCK TABLES, ON [Database to be migrated].* TO 'user1';

    Full migration:

    SELECT, CREATE, ALTER, DROP, DELETE, INSERT, UPDATE, INDEX, EVENT, CREATE VIEW, CREATE ROUTINE, TRIGGER, REFERENCES, and WITH GRANT OPTION. If the destination database version is in the range 8.0.14 to 8.0.18, the SESSION_VARIABLES_ADMIN permission is required.

    Reference statement: GRANT SELECT, CREATE, ALTER, DROP, DELETE, INSERT, UPDATE, INDEX, EVENT, CREATE VIEW, CREATE ROUTINE, TRIGGER ON *.* TO 'user1' WITH GRANT OPTION;

    Full+incremental migration:

    SELECT, CREATE, ALTER, DROP, DELETE, INSERT, UPDATE, INDEX, EVENT, CREATE VIEW, CREATE ROUTINE, TRIGGER, REFERENCES, and WITH GRANT OPTION. If the destination database version is in the range 8.0.14 to 8.0.18, the SESSION_VARIABLES_ADMIN permission is required.

    Reference statement: GRANTSELECT, CREATE, ALTER, DROP, DELETE, INSERT, UPDATE, INDEX, EVENT, CREATE VIEW, CREATE ROUTINE, TRIGGER, REFERENCES ON [Databases to be migrated].* TO 'user1' WITH GRANT OPTION;

    Real-time synchronization

    SELECT, SHOW VIEW, EVENT, LOCK TABLES, REPLICATION SLAVE, and REPLICATION CLIENT

    • REPLICATION SLAVE and REPLICATION CLIENT are global permissions and must be enabled separately. The reference statement is as follows:

      GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'user1';

    • SELECT, SHOW VIEW, EVENT, and LOCK TABLES are non-global permissions. The reference statement is as follows:

      GRANT SELECT, SHOW VIEW, EVENT, LOCK TABLES, ON [Database to be synchronized].* TO 'user1';

    The root account of RDS for MySQL has the following permissions by default: SELECT, CREATE, DROP, DELETE, INSERT, UPDATE, ALTER, CREATE VIEW, CREATE ROUTINE, and REFERENCES If the destination database version is in the range 8.0.14 to 8.0.18, the SESSION_VARIABLES_ADMIN permission is required.

    Reference statement: GRANT SELECT, CREATE, DROP, DELETE, INSERT, UPDATE, ALTER, REFERENCES ON [Databases to be migrated].* TO 'user1';

    Real-time disaster recovery

    The user root of the RDS for MySQL instance has the following permissions by default: SELECT, CREATE, ALTER, DROP, DELETE, INSERT, UPDATE, TRIGGER, REFERENCES, SHOW VIEW, EVENT, INDEX, LOCK TABLES, CREATE VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, RELOAD, REPLICATION SLAVE, REPLICATION CLIENT, and WITH GRANT OPTION If the service database version is 8.0.14 to 8.0.18, the SESSION_VARIABLES_ADMIN permission is required.

    Reference statements: GRANT SELECT,CREATE,ALTER,DROP,DELETE,INSERT,UPDATE,TRIGGER,SHOW VIEW,EVENT,INDEX,LOCK TABLES,CREATE VIEW,CREATE ROUTINE,ALTER ROUTINE,CREATE USER,RELOAD,REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO 'user1';

    The user root of the RDS for MySQL instance has the following permissions by default: SELECT, CREATE, ALTER, DROP, DELETE, INSERT, UPDATE, TRIGGER, REFERENCES, SHOW VIEW, EVENT, INDEX, LOCK TABLES, CREATE VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, RELOAD, REPLICATION SLAVE, REPLICATION CLIENT, and WITH GRANT OPTION If the DR database version is 8.0.14 to 8.0.18, the SESSION_VARIABLES_ADMIN permission is required.

    Reference statements: GRANT SELECT,CREATE,ALTER,DROP,DELETE,INSERT,UPDATE,TRIGGER,REFERENCES,SHOW VIEW,EVENT,INDEX,LOCK TABLES,CREATE VIEW,CREATE ROUTINE,ALTER ROUTINE,CREATE USER,RELOAD,REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO 'user1'@'%' WITH GRANT OPTION;

    Run flush privileges; after executing the preceding reference statements. Make the authorization take effect.

  • Account migration:

    The user must have the SELECT permission of mysql.user if the source database is a non-Alibaba Cloud database. If the source database is an Alibaba Cloud database, the account must have the SELECT permission of mysql.user and mysql.user_view.

    Reference statement:

    GRANT SELECT ON mysql.user TO 'user1'@'host' ;

    GRANT SELECT ON mysql.user_view TO 'user1';

    The destination database users must have the SELECT, INSERT, UPDATE, DELETE, and WITH GRANT OPTION permissions on all databases.

    Reference statement: GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'user1' WITH GRANT OPTION

Actions

  • Create a user.

    Operation:

    CREATE USER 'username'@'host' IDENTIFIED BY 'password';

    · username: indicates the account to be created.

    · host: indicates the host that allows the account to log in. If the account is allowed to log in to the database from any host, use %.

    · password: indicates the password of the account.

    For example, run the following command to grant the drsmigration account with all permissions on all databases and tables and allow the drsmigration account to log in to the database from any host:

    CREATE USER 'drsmigration'@'%' IDENTIFIED BY 'Drs123456';

  • Grant corresponding permissions.

    Operation:

    GRANT privileges ON databasename.tablename TO 'username'@'host' WITH GRANT OPTION;

    flush privileges;

    · privileges: indicates the operation permissions granted to the account, such as SELECT, INSERT, and UPDATE. To grant all permissions to the account, use ALL.

    · databasename: indicates the database name. To grant the account with all database operation permissions, use *.

    · tablename: indicates table name. To grant the account with all table operation permissions, use *.

    · username: indicates the account to be authorized.

    · host: indicates the host that allows the account to log in. If the account is allowed to log in from any host, use %.

    · WITH GRANT OPTION: indicates that the permission to use the GRANT command is granted to the account. This parameter is optional.

    For example, run the following command to create an account drsmigration with the password Drs123456 and allow the account to log in to the database from any host:

    GRANT ALL ON *.* TO 'drsmigration'@'%';