1949
MySQLERRORNotableTransactionHIGH confidence

Cannot change schema for a multi-schema transaction

Production Risk

Medium — transaction may be rolled back; use fully qualified names.

What this means

An attempt was made to change the default schema (database) using USE inside a multi-table transaction that spans multiple schemas, which MySQL prohibits.

Why it happens
  1. 1Issuing USE db2 inside an active transaction that already accessed tables in db1.
  2. 2Application-level connection pooling switching databases mid-transaction.
How to reproduce
trigger — this will error
trigger — this will error
START TRANSACTION;
SELECT * FROM db1.t;
USE db2; -- error

expected output

ERROR 1949 (HY000): Cannot change schema for a multi-schema transaction.

Fix

Fully qualify table names and avoid USE inside transactions

Fully qualify table names and avoid USE inside transactions
START TRANSACTION;
SELECT * FROM db1.t;
SELECT * FROM db2.t; -- use fully qualified names
COMMIT;

Why this works

Using schema.table notation removes the need to switch the default database mid-transaction.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 1949 ER_FORBID_SCHEMA_CHANGE

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MySQL errors