迁移MySQL用户及权限

导出


[root@db01 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
[root@db01 tmp]# cat /tmp/mysql_all_users.txt    
[root@db01 tmp]# cd /tmp/    
[root@db01 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    
[root@db01 tmp]# cat mysql_all_users_sql.sql    
[root@db01 tmp]# sed -i 's/$/;/' mysql_all_users_sql.sql    
[root@db01 tmp]# cat mysql_all_users_sql.sql    
[root@db01 tmp]# echo "flush privileges;" >> mysql_all_users_sql.sql


导入


[root@db02 tmp]# mysql -u root -p < mysql_all_users_sql.sql


你可能感兴趣的:(迁移MySQL用户及权限)