Tuesday, July 10, 2012

MySQL: Dumping With Users and Privileges

A gotcha when trying to clone an entire MySQL DB is that the user privileges are not completely cloned.

The following command would have resulted in users and privileges being cloned (since the "mysql" database would have been dumped), but they do not take effect until a "FLUSH PRIVILEGES" command has been issued:

mysqldump --all-databases > db.sql

This means additional manual step of issuing the "FLUSH PRIVILEGES" command is needed before the DB is usable.

In order to ensure that the "FLUSH PRIVILEGES" command is run during DB restore (so no additional steps needed to get DB up and running), include the "--flush-privileges" option during the dump.

mysqldump --all-databases --flush-privileges > db.sql

No comments:

Post a Comment