Skip to content

Instantly share code, notes, and snippets.

@wincus
Created April 21, 2015 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wincus/502795154b1804b6fa1c to your computer and use it in GitHub Desktop.
Save wincus/502795154b1804b6fa1c to your computer and use it in GitHub Desktop.
Export mysql users from master db
#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