Created
April 21, 2015 21:22
-
-
Save wincus/502795154b1804b6fa1c to your computer and use it in GitHub Desktop.
Export mysql users from master db
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#export users in sql format | |
mysql -B -N -u${USER} -p${PASS} -h${HOST} -e "SELECT DISTINCT CONCAT('SHOW GRANTS FOR ''', user, '''@''', host, ''';') AS query FROM mysql.user" | \ | |
mysql -u${USER} -p${PASS} -h${HOST} | \ | |
sed 's/\(GRANT .*\)/\1;/;s/^\(Grants for .*\)/## \1 ##/;/##/{x;p;x;}' | \ | |
gzip -c > ${HOST}/user-grants.sql.gz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment