Skip to content

Instantly share code, notes, and snippets.

@epleterte
Created March 19, 2013 14:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save epleterte/5196601 to your computer and use it in GitHub Desktop.
Save epleterte/5196601 to your computer and use it in GitHub Desktop.
mygrants!
# cool mysql grants printing function (producing proper sql) - http://serverfault.com/a/13050
# example:
# mygrants --host=prod-db1 --user=admin --password=secret | grep rails_admin | mysql --host=staging-db1 --user=admin --password=secret
mygrants()
{
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