Backup MySQL users

Cherian picture Cherian · Feb 28, 2009 · Viewed 44.4k times · Source

How do I backup MySQL users and their privileges?

Anything like mysqldump?

I am looking for something like:

mysqldump -d -u root -p MyTable > Schema.sql

Answer

spirit picture spirit · Feb 23, 2012
mysql -BNe "select concat('\'',user,'\'@\'',host,'\'') from mysql.user where user != 'root'" | \
while read uh; do mysql -BNe "show grants for $uh" | sed 's/$/;/; s/\\\\/\\/g'; done > grants.sql