Skip to content

Instantly share code, notes, and snippets.

@cheneyveron
Created April 17, 2019 15:15
Show Gist options
  • Save cheneyveron/870e6c55221b4ef7240a3e773d917b5c to your computer and use it in GitHub Desktop.
Save cheneyveron/870e6c55221b4ef7240a3e773d917b5c to your computer and use it in GitHub Desktop.
mysql -u<user> -p<pass> -h<host> -e"select concat('show grants for ','\'',user,'\'@\'',host,'\'') from mysql.user" > user_list_with_header.txt
sed '1d' user_list_with_header.txt > ./user.txt
while read user; do mysql -u<user> -p<pass> -h<host> -e"$user" > user_grant.txt; sed '1d' user_grant.txt >> user_privileges.txt; echo "flush privileges" >> user_privileges.txt; done < user.txt
awk '{print $0";"}' user_privileges.txt >user_privileges_final.sql
rm user.txt user_list_with_header.txt user_grant.txt user_privileges.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment