首页 > 代码库 > 迁移MySQL用户及权限
迁移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
本文出自 “SQL Server Deep Dive” 博客,请务必保留此出处http://ultrasql.blog.51cto.com/9591438/1924469
迁移MySQL用户及权限