Created
November 8, 2018 11:23
-
-
Save osoda/1ba694e236cade803499337a340655ce to your computer and use it in GitHub Desktop.
Give all user and privileges ready to execute in a query sql. To migrate mysql users
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
mysql -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 -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