Skip to content

Instantly share code, notes, and snippets.

@OJezu
Created June 4, 2020 12:25
Show Gist options
  • Save OJezu/971e357365e5465a062759c16a855b4d to your computer and use it in GitHub Desktop.
Save OJezu/971e357365e5465a062759c16a855b4d to your computer and use it in GitHub Desktop.
Dump all users and priviledges on MySQL server
#!/bin/sh
mysql "$@" -AN <<'SQL'
SELECT CONCAT('CREATE USER ', QUOTE(user), '@', QUOTE(host), ' IDENTIFIED WITH ', QUOTE(plugin), ' AS ', QUOTE(authentication_string), ';')
FROM mysql.user WHERE user<>'' AND host<>''
ORDER BY user, host
;
SQL
mysql "$@" -AN <<'SQL' | mysql "$@" | sed 's/$/;/;/^Grants for /d'
SELECT CONCAT('SHOW GRANTS FOR ',QUOTE(user),'@',QUOTE(host),';')
FROM mysql.user WHERE user<>'' AND host<>''
ORDER BY user, host
;
SQL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment