Created
September 4, 2018 12:48
-
-
Save ppar/8511474d6e1c34f9f85461f76e1286bc to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/bash | |
# mygrants.sh | |
# | |
# This script dumps all grants for all users in MySQL as an SQL script that you can pipe back to mysql | |
# | |
# USAGE: ./mygrants.sh [command line options to mysql, e.g. login] | |
# | |
mysql -B -N $@ \ | |
-e "SELECT DISTINCT CONCAT('SHOW GRANTS FOR \'', user, '\'@\'', host, '\';') AS query FROM mysql.user" | | |
while read cmd ; do | |
echo "## ${cmd}" | |
echo "${cmd}" | mysql -N $@ | |
echo | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment