Skip to content

Instantly share code, notes, and snippets.

@pstaender
Created February 12, 2015 16:04
Show Gist options
  • Select an option

  • Save pstaender/f255ba2caa1b914979d7 to your computer and use it in GitHub Desktop.

Select an option

Save pstaender/f255ba2caa1b914979d7 to your computer and use it in GitHub Desktop.
Dump MySQL Privileges to import in an existing / other database
#!/bin/sh
# from https://saiyedfaishal.wordpress.com/2014/03/20/exporting-all-mysql-user-privileges/
HOST="127.0.0.1";USER="root";PASSWORD="root";mysql -h $HOST -u $USER -p$PASSWORD -Ne "select distinct concat( \"SHOW GRANTS FOR '\",user,\"'@'\",host,\"';\" ) from user;" mysql | mysql -h $HOST -u $USER -p$PASSWORD | sed 's/\(GRANT .*\)/\1;/;s/^\(Grants for .*\)/## \1 ##/;/##/{x;p;x;}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment