til icon indicating copy to clipboard operation
til copied to clipboard

Export the privileges from MySQL and import to another server

Open xluffy opened this issue 3 years ago • 0 comments

Method 1 - Bash

> _my_grants()
{
  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;}'
}

> _my_grants > users.sql

Method 2 - Percona Toolkits

> pt-show-grants > users.sql

xluffy avatar Sep 07 '21 14:09 xluffy