We use a database cluster. When I export the database I run the following command:
mysqldump --single-transaction --quick -u[user] -p[password] -h[host] -P[port number] [database] > [path]
I use homestead to work locally, and to import the database I execute this command:
mysql -uhomestead -psecret -D [database] < [file.sql]
But I receive an error message:
ERROR 1840 (HY000) at line 24: @@GLOBAL.GTID_PURGED can only be set when @@GLOBAL.GTID_EXECUTED is empty.
This is the first time I have this error. What does it mean? What is the correct way to export / import?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hello,
What you could try is to open the .sql dump file and remove the GLOBAL statement from line 24. Then try the import again.
Hope that this helps! Regards, Bobby
The error you’re encountering:
ERROR 1840 (HY000) at line 24: @@GLOBAL.GTID_PURGED can only be set when @@GLOBAL.GTID_EXECUTED is empty.
occurs because you’re working with a GTID (Global Transaction ID)-enabled MySQL cluster. When exporting a database from a cluster with GTIDs enabled, the mysqldump command captures the GTID state in the dump file, including the @@GLOBAL.GTID_PURGED variable. This variable holds information about the transactions that have been purged and is relevant in a GTID environment.
However, when importing this dump file into a different MySQL instance (like your local environment with Homestead), if GTIDs are not enabled or not used in the same way, this causes the conflict you’re seeing. The error indicates that @@GLOBAL.GTID_PURGED can only be set when the @@GLOBAL.GTID_EXECUTED is empty (i.e., when no transactions have been executed on the target MySQL instance).
--set-gtid-purged=OFF option in the mysqldump command.Example:
mysqldump --single-transaction --quick --set-gtid-purged=OFF -u[user] -p[password] -h[host] -P[port number] [database] > [path]
This option ensures that the GTID information is not included in the dump file, making it compatible with databases that don’t use GTIDs (such as your local Homestead environment).
SET @@GLOBAL.GTID_PURGED=) from the SQL file before importing it.Steps:
SET @@GLOBAL.GTID_PURGED and remove them.mysql command.mysql -uhomestead -psecret -D [database] < [file.sql]
The error is due to the GTID information that is part of the database cluster. To avoid this error, you can either:
--set-gtid-purged=OFF when exporting the database, orThis will make the export/import process compatible with your local setup where GTIDs may not be in use.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.