Monday, March 28, 2011

How to copy export mySQL user priviledges

 Copy/Export MySQL User Priviledges

I’m often asked how to copy or export MySQL Users from one machine to another. The following SQL query will show your users:
SELECT DISTINCT CONCAT (‘show grants for `’, user, ‘`@`’, host, ‘`;’) AS query FROM mysql.user;
In my case on my test server, this shows:
SHOW GRANTS FOR ‘root’@’127.0.0.1′;
SHOW GRANTS FOR ‘debian-sys-maint’@'localhost’;
SHOW GRANTS FOR ‘root’@'localhost’;
Now, I’ll need to execute each one of these as separate statements. The output of SHOW GRANTS FOR ‘root’@'localhost’; is:
GRANT ALL PRIVILEGES ON *.* TO ‘root’@'localhost’ IDENTIFIED BY PASSWORD ‘*XXX…XXX’ WITH GRANT OPTION;
Copy and paste each ‘GRANT’ statement to your new SQL server, with the hashed password intact and you should be ready to go.

No comments:

Post a Comment