This is ericpony's blog

Wednesday, August 29, 2012

Exporting MySQL Privilege Settings

function 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;}'
}

Usage: mygrants --host=[HOST] --user=[USER] --password=[PASSWORD]

Author: Richard Bronosky

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...