I've taken a mysql dump of a database using the command:
mysqldump --single-transaction --all-databases --flush-privileges -h HOST -u USER -p PASSWORD
I purposefully used the --all-databases
flag to make sure that I got all the users I had created and the permissions they had granted. But when I run the import to a new database as the root user, I get this error: Access denied for user 'root'@'%' to database 'mysql'
Is there a different way to copy over users and permissions from one database to another?
I use a SHOW GRANTS statement to get the privileges, for example:
SHOW GRANTS FOR foo@'%'
Which returns something like this:
Grants for foo@%
--------------------------------------------------------------------------------------------------
GRANT USAGE ON *.* TO 'foo'@'%' IDENTIFIED BY PASSWORD '*B3CD------------------------------------'
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE TEMPORARY TABLES, EXECUTE ON `db`.* TO 'foo'@'%'
GRANT SELECT ON `mysql`.`proc` TO 'foo'@'%'
I can easily take the output, add the semicolon statement terminators, make any other necessary modifications, and execute them on another database.
And just repeat that for whichever users I need to migrate.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.