简体   繁体   English

使用mysql转储的授权填充mysql数据库

[英]Populating mysql database with grants from mysql dump

I've taken a mysql dump of a database using the command: 我使用以下命令进行了数据库的mysql转储:

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. 我故意使用--all-databases标志来确保我获得了我创建的所有用户以及他们授予的权限。 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' 但是当我以root用户身份运行导入到新数据库时,我收到此错误: 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语句来获取权限,例如:

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. 对于我需要迁移的用户,请重复一遍。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM