Skip to content

Instantly share code, notes, and snippets.

@morhekil
Created January 6, 2013 08:06
Show Gist options
  • Save morhekil/4465971 to your computer and use it in GitHub Desktop.
Save morhekil/4465971 to your computer and use it in GitHub Desktop.
shell script to dump existing MySQL privileges as GRANT commands
#!/usr/bin/bash
mysql -B -N $@ -e "SELECT DISTINCT CONCAT(
'SHOW GRANTS FOR ''', user, '''@''', host, ''';'
) AS query FROM mysql.user" | \
mysql $@ | \
sed 's/\(GRANT .*\)/\1;/;s/^\(Grants for .*\)/## \1 ##/;/##/{x;p;x;}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment