Skip to content

Instantly share code, notes, and snippets.

@inxilpro
Created November 25, 2014 20:53
Show Gist options
  • Select an option

  • Save inxilpro/8f72001f82672727df7c to your computer and use it in GitHub Desktop.

Select an option

Save inxilpro/8f72001f82672727df7c to your computer and use it in GitHub Desktop.
Export all MySQL user permissions
read -s -p "Enter MySQL password for root: " root_password
root_password=$(printf '%q' $root_password)
grants_command='SELECT DISTINCT CONCAT("SHOW GRANTS FOR `", user, "`@`", host, "`;") AS "query" FROM `mysql`.`user`;'
grants=$(mysql -N -s --user=root --password=$root_password --execute="$grants_command")
mysql -N -s -r --user=root --password=$root_password --execute="$grants"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment