Created
June 8, 2011 20:55
-
-
Save abarringer/1015377 to your computer and use it in GitHub Desktop.
Move MySQL Users with Permissions to New Server
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
#!/bin/bash | |
mygrants() | |
{ | |
mysql -B -N $@ -e "SELECT DISTINCT CONCAT( | |
'SHOW GRANTS FOR ''', user, '''@''', host, ''';' | |
) AS query FROM mysql.user" | \ | |
mysql $@ | \ | |
sed 's/\(GRANT .*\)/\1;/;s/^\(Grants for .*\)/## \1 ##/;/##/{x;p;x;}' | |
} | |
mygrants --host=localhost -uroot -p |
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
select | |
concat('CREATE USER ''', user, '''@''', host, ''' IDENTIFIED BY PASSWORD ''', password,''';') | |
from mysql.user | |
where user not in ('root', 'debian-sys-maint', ''); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment