MySQL管理工具MySQL Utilities — 创建具有相同权限的新用户(34)

默北 MySQLMySQL管理工具MySQL Utilities — 创建具有相同权限的新用户(34)已关闭评论7,186字数 742阅读2分28秒阅读模式

在有些场景下,我们需要创建一个与已有的用户具有相同权限的用户。一般情况下,我们是先通过SHOW GRANTS FOR语句来查看已有的用户权限,然后复制、修改再执行GRANT语句来创建新的用户。

现在我们可以通过mysqluserclone 命令给一个用户复制到新的用户,甚至可以设置不同的密码和用户名。文章源自运维生存时间-https://www.ttlsa.com/mysql/creating-new-user-with-the-same-privileges/

假如有个用户 joe@localhost ,现在我们需要创建两个具有相同权限的用户sally 和 john,并各自有各自的新密码,分别为www.ttlsa.com和bbs.ttlsa.com。文章源自运维生存时间-https://www.ttlsa.com/mysql/creating-new-user-with-the-same-privileges/

实例

shell> mysqluserclone --source=root@localhost \
          --destination=root@localhost \
          joe@localhost sally:www.ttlsa.com@localhost john:bbs.ttlsa.com@localhost
# Source on localhost: ... connected.
# Destination on localhost: ... connected.
# Cloning 2 users...
# Cloning joe@localhost to user sally:www.ttlsa.com@localhost
# Cloning joe@localhost to user bbs.ttlsa.com:secret2@localhost
# ...done.

新用户格式为:username:password@host  来指定用户名、密码和允许连接的主机名。文章源自运维生存时间-https://www.ttlsa.com/mysql/creating-new-user-with-the-same-privileges/

权限

在源服务器上,用户必须拥有对mysql数据库的SELECT权限。文章源自运维生存时间-https://www.ttlsa.com/mysql/creating-new-user-with-the-same-privileges/

在目标服务器上,用户必须具有全局的CREATE USER权限或对mysql数据库的INSERT权限,以及GRANT OPTION权限。文章源自运维生存时间-https://www.ttlsa.com/mysql/creating-new-user-with-the-same-privileges/ 文章源自运维生存时间-https://www.ttlsa.com/mysql/creating-new-user-with-the-same-privileges/

weinxin
我的微信
微信公众号
扫一扫关注运维生存时间公众号,获取最新技术文章~
默北
  • 本文由 发表于 25/03/2015 01:00:30
  • 转载请务必保留本文链接:https://www.ttlsa.com/mysql/creating-new-user-with-the-same-privileges/