导出
[[email protected] tmp]# mysql -B -N -uroot -p -e "SELECT CONCAT(‘\‘‘, user,‘\‘@\‘‘, host, ‘\‘‘) FROM user WHERE user != ‘debian-sys-maint‘ AND user != ‘root‘ AND user != ‘‘" mysql > /tmp/mysql_all_users.txt
[[email protected] tmp]# cat /tmp/mysql_all_users.txt
[[email protected] tmp]# cd /tmp/
[[email protected] tmp]# while read line; do mysql -B -N -uroot -predhat -e "SHOW GRANTS FOR $line"; done < mysql_all_users.txt > mysql_all_users_sql.sql
[[email protected] tmp]# cat mysql_all_users_sql.sql
[[email protected] tmp]# sed -i ‘s/$/;/‘ mysql_all_users_sql.sql
[[email protected] tmp]# cat mysql_all_users_sql.sql
[[email protected] tmp]# echo "flush privileges;" >> mysql_all_users_sql.sql
导入
[[email protected] tmp]# mysql -u root -p < mysql_all_users_sql.sql