Exporting all MySQL user privileges

To export all MySQL user privileges run following script.

Note : Replace {host_name}, {user_name} and {password} with your values.

mysql -h {host_name} -u {user_name} -p{password} -Ne "select distinct concat( \"SHOW GRANTS FOR '\",user,\"'@'\",host,\"';\" ) from user;" mysql | mysql -h {host_name} -u {user_name} -p{password} | sed 's/\(GRANT .*\)/\1;/;s/^\(Grants for .*\)/## \1 ##/;/##/{x;p;x;}'

Above script will generate all grants statements.You can then take that output and run the statements against MySQL on the new server.