Error
Error Code:
1781
MySQL Error 1781: GTID_NEXT with GTID_MODE Off
Description
This error indicates an attempt to manually set the `@@SESSION.GTID_NEXT` variable to a Global Transaction Identifier (GTID) value (UUID:NUMBER) when the global GTID mode (`@@GLOBAL.GTID_MODE`) is currently disabled. GTID_NEXT is crucial for GTID-based replication and requires GTIDs to be active on the server. This typically happens during replication setup or specific data loading scenarios.
Error Message
@@SESSION.GTID_NEXT cannot be set to UUID:NUMBER when @@GLOBAL.GTID_MODE = OFF.
Known Causes
3 known causesAttempting GTID Operations on Disabled Server
The server's global GTID mode (`@@GLOBAL.GTID_MODE`) is set to `OFF`, but an operation, typically related to replication or data loading, tries to set `@@SESSION.GTID_NEXT`.
Manual Session GTID Assignment
A user or application manually executes a `SET @@SESSION.GTID_NEXT = 'UUID:NUMBER'` statement without verifying that the server's GTID mode is enabled.
Executing GTID-Aware Scripts on Non-GTID Server
A SQL script or application designed to work with GTID-based replication or data import (e.g., using `SET GTID_NEXT` for specific transactions) is run on a server where GTIDs are globally disabled.
Solutions
3 solutions available1. Temporarily Enable GTID for Session easy
Enable GTID for the current session to allow setting GTID_NEXT.
1
Connect to your MySQL server using a client that allows session variable setting.
2
Set the `GTID_MODE` to `ON` for the current session. This is a temporary change and will not affect the global setting.
SET SESSION GTID_MODE = ON;
3
Now, you can set the `GTID_NEXT` variable for the session. Replace `UUID:NUMBER` with the actual GTID you intend to set.
SET SESSION GTID_NEXT = 'your_uuid:your_number';
4
Proceed with your operation that requires setting `GTID_NEXT`.
5
Once done, you can optionally reset the session `GTID_MODE` to `OFF` if that was its previous state, although it's not strictly necessary as it's session-specific.
SET SESSION GTID_MODE = OFF;
2. Globally Enable GTID Mode medium
Permanently enable GTID mode for the entire MySQL instance.
1
Log in to your MySQL server as a user with `SUPER` or `SYSTEM_VARIABLES_ADMIN` privileges.
2
Check the current global `GTID_MODE` setting.
SHOW GLOBAL VARIABLES LIKE 'gtid_mode';
3
If `gtid_mode` is `OFF`, you need to change it. This requires a server restart if the change is made directly in the configuration file. For a dynamic change that persists after restart, modify the configuration file.
4
Edit your MySQL configuration file (e.g., `my.cnf` or `my.ini`). Locate the `[mysqld]` section and add or modify the `gtid_mode` setting to `ON`.
[mysqld]
gtid_mode = ON
enforce_gtid_consistency = ON
5
Save the configuration file and restart your MySQL server.
6
After the server restarts, verify that `GTID_MODE` is `ON` globally.
SHOW GLOBAL VARIABLES LIKE 'gtid_mode';
7
Now you can set `GTID_NEXT` at the session level without encountering the error.
SET SESSION GTID_NEXT = 'your_uuid:your_number';
3. Disable GTID_NEXT Setting easy
Avoid setting GTID_NEXT if GTID_MODE is OFF and not explicitly required.
1
Review the operation or script that is attempting to set `@@SESSION.GTID_NEXT`.
2
Determine if setting `GTID_NEXT` is truly necessary for the intended operation in an environment where `GTID_MODE` is `OFF`.
3
If `GTID_NEXT` is not essential for your operation when `GTID_MODE` is `OFF`, remove or comment out the line that sets `@@SESSION.GTID_NEXT`.
/* SET SESSION GTID_NEXT = 'your_uuid:your_number'; */
4
Re-run your operation without attempting to set `GTID_NEXT`.