导出所有用户的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;