Import all grant statement of users in mysql schema !

us_yunleiwang發表於2013-12-06
匯出所有使用者的grant sql語句:

mysql --default-character-set=utf8 -e "SELECT CONCAT('show grants for ''',USER,'''@''',HOST,''';') as gsql  FROM mysql.user WHERE USER NOT IN('','root');" > g1.log;

sed -i '1d' g1.log
# sed 's/gsql//g' g1.log > g2.log;
> g3.sql;

sed -n '2,$p' g1.log|while read var
do
    #cnt=(`mysql -N -s --default-character-set=utf8 -e "select count(*) from "$var`)
    #echo $var
    mysql --default-character-set=utf8 -e "$var" >> g3.sql;
done

sed 's/$/&;/g' g3.sql > g4.sql;
sed  '/Grants for/d' g4.sql > g5.sql;

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23490154/viewspace-1062535/,如需轉載,請註明出處,否則將追究法律責任。

相關文章