mysql导出用户权限
2019-09-09mysql迁移用户前,需要查询
#!/bin/bash
#Function export user privileges
exp_grants()
{
mysql -B -u'root' -p'123456' -N $@ -e "SELECT CONCAT(
'SHOW GRANTS FOR ''', user, '''@''', host, ''';'
) AS query FROM mysql.user" | \
mysql -u'root' -p'123456' $@ | \
sed 's/\(GRANT .*\)/\1;/;s/^\(Grants for .*\)/-- \1 /;/--/{x;p;x;}'
}
exp_grants > ./results.sql