<p>Raised when a session tries to change @@session.binlog_direct_non_transactional_updates while a transaction is active.</p>
<p>MySQL Error 1685: ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_DIRECT occurs when you set @@session.binlog_direct_non_transactional_updates inside an open transaction. Commit or roll back first, then rerun the SET, or configure the variable globally before any transaction to resolve the issue.</p>
Cannot modify
MySQL throws error 1685 when a client attempts to modify the session variable @@session.binlog_direct_non_transactional_updates while a transaction is already in progress. The server blocks the change to maintain binary log consistency.
The condition name ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_DIRECT makes it clear that an active transaction prevents switching the binlog_direct_non_transactional_updates flag. The error appears immediately after the SET statement.
The error is triggered by executing SET @@session.binlog_direct_non_transactional_updates = 1 or 0 within a BEGIN ... COMMIT or START TRANSACTION block. MySQL mandates that the variable be set before any transactional statement.
Another common cause is client frameworks that disable autocommit, creating implicit transactions. A mid-session SET then fails because the session is never truly outside a transaction.
Commit or roll back the current transaction, then reissue the SET command. This simple sequence clears the transactional context and allows the variable change.
You can also define the variable globally or at connection startup so it never needs modification during a transaction. This strategy works well with connection pools and batch jobs.
Migration scripts that bundle variable changes with DML often hit this error. Split the script so the SET command runs alone, followed by a new transaction for data updates.
In connection pools with autocommit OFF, place SET @@session.binlog_direct_non_transactional_updates = 1 in the initialization SQL so every new session starts with the correct value.
Always set session variables affecting binary logging before beginning any transaction. Make it part of your application startup routine or session initialization.
Add error 1685 monitoring to DBA dashboards. Quick detection pinpoints clients that attempt mid-transaction variable switches.
Error 1663 ER_CANT_CHANGE_TX_CHARACTERISTICS_DRIVED blocks changing isolation levels inside a transaction. Commit, then change the level.
Error 1224 ER_WARNING_NOT_COMPLETE_ROLLBACK signals an incomplete rollback when autocommit is OFF. Review transaction boundaries and retry.
Issuing SET @@session.binlog_direct_non_transactional_updates inside an explicit transaction triggers error 1685.
With autocommit disabled, every statement runs inside a transaction, making mid-session SET commands illegal.
Migrations or ORM batches often mix variable toggles and data changes, unintentionally causing the error.
Raised when changing isolation level inside a transaction. Commit first, then alter the level.
Occurs when attempting writes in read-only mode. Switch to read-write or end the read-only transaction.
Indicates a rollback could not undo all changes. Inspect binary log for partial commits.
No. MySQL enforces it to protect binary log integrity. You can only change the variable outside a transaction.
Yes. With autocommit ON, each statement is its own transaction, leaving no open transaction when you run the SET.
The restriction exists in MySQL 5.7, 8.0, and later releases with identical behavior.
Galaxy highlights open transactions, lets you run SET statements separately, and provides snippets that commit first, reducing the chance of error 1685.