Skip to content

Instantly share code, notes, and snippets.

@epleterte
Created March 19, 2013 14:30
Show Gist options
  • Select an option

  • Save epleterte/5196601 to your computer and use it in GitHub Desktop.

Select an option

Save epleterte/5196601 to your computer and use it in GitHub Desktop.

Revisions

  1. epleterte created this gist Mar 19, 2013.
    11 changes: 11 additions & 0 deletions mygrants.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    # 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;}'
    }