mysql -h 'host' -u 'user' -p -N $@ -e "SELECT CONCAT('SHOW GRANTS FOR ''', user, '''@''', host, ''';') AS query FROM mysql.user" > /tmp/users.sql
host indicates the IP address of the source database and user indicates the username of the source database.
mysql -h 'host' -u 'user' -p -N $@ -e "source /tmp/users.sql" > /tmp/grants.sql
sed -i 's/$/;/g' /tmp/grants.sql
host indicates the IP address of the source database and user indicates the username of the source database.
-- Grants for root@% GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'; -- Grants for testt@% GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'testt'@'%'; -- Grants for debian-sys-maint@localhost GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' WITH GRANT OPTION; -- Grants for mysql.session@localhost GRANT SUPER ON *.* TO 'mysql.session'@'localhost'; GRANT SELECT ON `performance_schema`.* TO 'mysql.session'@'localhost'; GRANT SELECT ON `mysql`.`user` TO 'mysql.session'@'localhost'; -- Grants for mysql.sys@localhost GRANT USAGE ON *.* TO 'mysql.sys'@'localhost'; GRANT TRIGGER ON `sys`.* TO 'mysql.sys'@'localhost'; GRANT SELECT ON `sys`.`sys_config` TO 'mysql.sys'@'localhost'; -- Grants for root@localhost GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION; GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION;