NewDTS focuses more on the data content itself during MySQL data migration. It migrates basic tables and views only but not user permission information. This document describes how to migrate user permissions.
In this document, pt-show-grants is used to export user permissions from the source database and import them to the target database.
dts
user as an example:CREATE USER 'dts'@'%' IDENTIFIED BY 'migration password';
GRANT SELECT ON `mysql`.* TO 'dts'@'%';
dts
user as an example: CREATE USER 'dts'@'%' IDENTIFIED BY 'migration password';
GRANT SELECT,CREATE USER,LOCK TABLES,SHOW VIEW,TRIGGER,ALTER,ALTER ROUTINE,CREATE,CREATE ROUTINE,CREATE TABLESPACE,CREATE TEMPORARY TABLES,CREATE VIEW,DELETE,DROP,EVENT,EXECUTE, INDEX,INSERT,PROCESS,REFERENCES,RELOAD,UPDATE,SHOW DATABASES on *.* to 'dts'@'%';
FLUSH PRIVILEGES;
read_only
user as an example:CREATE USER 'read_only'@'%' IDENTIFIED BY 'migration password';
GRANT SELECT, SHOW DATABASES, SHOW VIEW on *.* to 'read_only'@'%';
FLUSH PRIVILEGES;
--ignore
to filter out high-privileged accounts that cannot be imported by MySQL.pt-show-grants --user=root --host=<src host or ip> --port=<src port> --user=<user> --password=<password> --ignore 'mysql.sys'@'localhost','mysql.session'@'localhost','mysql.infoschema'@'localhost','root','root'@'localhost' > account.sql
mysql -u<user> -p<password> -h<dst ip or host> -P<dst port> -e "source account.sql"
Below are sample SQL statements exported from MySQL 5.7.6 or above:-- Grants dumped by pt-show-grants
-- Dumped from server xxxx via TCP/IP, MySQL 8.0.22-txsql at 2021-09-01 11:28:21
-- Grants for 'dts'@'%'
CREATE USER IF NOT EXISTS 'dts'@'%';
ALTER USER 'dts'@'%' IDENTIFIED WITH 'mysql_native_password' AS '*F2XFE7135318FD1F12CDF7B027506096F223DDD46' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT PASSWORD REQUIRE CURRENT DEFAULT;
GRANT LOCK TABLES, PROCESS, RELOAD, REPLICATION CLIENT, REPLICATION SLAVE, SELECT, SHOW DATABASES, SHOW VIEW ON *.* TO `dts`@`%`;
GRANT SELECT ON `mysql`.* TO `dts`@`%`;
Below are sample SQL statements exported from MySQL below v5.7.6:-- Grants dumped by pt-show-grants
-- Dumped from server xxxx via TCP/IP, MySQL 5.6.16-log at 2021-09-01 11:33:53
-- Grants for 'dts'@'%'
GRANT LOCK TABLES, PROCESS, RELOAD, REPLICATION CLIENT, REPLICATION SLAVE, SELECT, SHOW VIEW ON *.* TO 'dts'@'%' IDENTIFIED BY PASSWORD '*47D7DB84D97A8D7EFD5B3CFA20A7A2433A9E86A4';
GRANT ALL PRIVILEGES ON `__tencentdb__`.* TO 'dts'@'%';
GRANT SELECT ON `mysql`.* TO 'dts'@'%';
Was this page helpful?