代码之家  ›  专栏  ›  技术社区  ›  hasanghaforian

备份与MySQL特定用户相关的所有权限

  •  0
  • hasanghaforian  · 技术社区  · 7 年前

    我想备份与特定用户相关的所有权限(例如 u_1 here , The 'mysql' database contains users/privileges/passwords. mysql 数据库( mysql.user , mysql.db , ...). 我可以运行此命令:

    $ mysqldump -u root --flush-privileges -r mysql.sql -p mysql
    

    但当然 mysql.sql .

    $ mysqldump -u root -p --where="user.user='u_1'" mysql user> mysql.sql
    

    但正如所料,它只包含一行 mysql。使用者 桌子

    ?

    2 回复  |  直到 7 年前
        1
  •  3
  •   Michael - sqlbot    7 年前

    $ mysqldump -u root -p 
      --where="user='u_1'"
      --complete-insert
      --extended-insert
      --no-create-info
      mysql 
      user db tables_priv columns_priv procs_priv proxies_priv 
      > mysql.sql
    

    或让我们称上述解决方案为“艰难之路”

    $ mysql -u root -p
      --skip-column-names
      -e "SHOW GRANTS FOR 'u_1';"
      > grants.sql
    
        2
  •  0
  •   Bill Karwin    7 年前

    我会使用:

    pt-show-grants --only u_1
    

    pt show grants是免费Percona工具包中的一个工具。

    https://www.percona.com/doc/percona-toolkit/LATEST/pt-show-grants.html