MySQL User Privileges Migration

During the MySQL version upgrade or for easy user backup you can you below.
 
To export all MySQL user privileges run following script.
  
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;}'

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

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

Comments

Popular posts from this blog

How do I Use the Linux Top Command?

IOPS measurement