zoukankan      html  css  js  c++  java
  • MySQL导出用户权限

    在MySQL 5.5/5.6版本中,使用SHOW GRANTS命令可以导出用户的创建脚本和授权脚本。

    hostname='127.0.0.1'
    port=3358
    username='root'
    password='abc@123.com'
    mysql_exe="/export/servers/mysql/bin/mysql"
    echo "select concat('show grants for ''',user,'''@''',host, ''';') from mysql.user where user <>'root'" | \
    ${mysql_exe} --host=$hostname --user=$username --password=$password --port=$port -N | \
    ${mysql_exe} --host=$hostname --user=$username --password=$password --port=$port -N | \
    sed "s/$/;/" > /tmp/create-users.sql

    在MySQL 5.7版本中,需要使用SHOW CRETAE USER命令导出用户创建脚本,然后使用SHOW GRANT命令导出用户授权脚本。

    hostname='127.0.0.1'
    port=3358
    username='root'
    password='abc@123.com'
    mysql_exe="/export/servers/mysql/bin/mysql"
    echo "select concat('show create user ''',user,'''@''',host, ''';','show grants for ''',user,'''@''',host, ''';') from mysql.user where user <>'root'" | \
    ${mysql_exe} --host=$hostname --user=$username --password=$password --port=$port -N | \
    ${mysql_exe} --host=$hostname --user=$username --password=$password --port=$port -N | \
    sed "s/$/;/" > /tmp/create-users.sql
  • 相关阅读:
    POJ2175 Evacuation Plan
    POJ3252 Round Numbers
    POJ2115 C Looooops
    POJ3422 Kaka's Matrix Travels
    POJ1659 Frogs' Neighborhood
    POJ2635 The Embarrassed Cryptographer
    POJ3436 ACM Computer Factory
    FZU1607 Greedy division
    EOJ440 Buying Feed
    POJ2135 Farm Tour
  • 原文地址:https://www.cnblogs.com/gaogao67/p/10372279.html
Copyright © 2011-2022 走看看