Created
April 22, 2014 22:52
-
-
Save jcook793/11197121 to your computer and use it in GitHub Desktop.
Generates MySQL GRANT statements for all users in a DB
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 | |
users_hosts=`mysql -B -N -e "select user, host from mysql.user;"` | |
echo "${users_hosts}" | while read user_host; do | |
user=`echo "${user_host}" | cut -f 1` | |
host=`echo "${user_host}" | cut -f 2` | |
if [ "${user}" != "root" ]; then | |
grants=`mysql -N -e "show grants for '${user}'@'${host}';"` | |
echo "${grants}" | while read grant; do | |
echo "${grant};" | |
done | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment