Mysql – Restoring a thesqldump loses user privileges for routines

gtidMySQLmysql-8.0mysqldump

When I try and restore a mysqldump, the user privileges against some routines are missing. From what I can tell that is happeneing the routines that are in schemas that are loaded after the mysql schema have no user privileges. (eg. Schema "abc" has the correct user privileges for routines but in schema "qrs" they are missing.)

The dump I am using is created by:

mysqldump --allow-keywords --all-databases --single-transaction --events --routines --flush-logs --flush-privileges --hex-blob

When I have run into this issue in the past I would load the dump and then reload just the mysql schema, which then gives the missing users privileges on the routines.

However recently I have started using GTIDs and as a result I can't reload the just the mysql schema from the dump as the GTIDs overlap, as when I try to do so i get this error:

@@GLOBAL.GTID_PURGED cannot be changed: the added gtid set must not overlap with @@GLOBAL.GTID_EXECUTED

Is there a way to reload a dump made this way and have all the user permissions be exactly the same after reloading the dump on another server?

Best Answer

You need to add the --set-gtid-purged=OFF flag to your mysqldump statement. This will stop it from writing the set-gtid-purged line in the dump file.