Following line will query all mysql user with their grants and print the creation statements for them.
By copy pasting or by filling a SQL-file, you can easily migrate all MySQL-user to a new mysql or mariaDB instance.
mysql -u root -p"YOUR_PW" -Ne "select distinct concat( \"SHOW GRANTS FOR '\",user,\"'@'\",host,\"';\" ) from mysql.user;" mysql | \
mysql -u root -p"YOUR_PW"| \
sed 's/\(GRANT .*\)/\1;/;s/^\(Grants for .*\)/## \1 ##/;/##/{x;p;x;}'
Leave a Reply