How to Fix MySQL Error 3979 (ER_NOT_ALLOWED_WITH_START_TRANSACTION)

Published
Length
3 min read

Luis Felipe Dias

All posts

You get mysql error 3979 when a start transaction clause conflicts with another setting. You fix it by removing the conflicting clause or running the commands apart. The database engine uses the symbol ER_NOT_ALLOWED_WITH_START_TRANSACTION and SQLSTATE HY000 for this issue. The engine blocks the request before any data changes happen. Knowing why the engine stops the query helps your team keep data safe. What causes mysql error 3979 in your database The official message says a start transact

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You get mysql error 3979 when a start transaction clause conflicts with another setting. You fix it by removing the conflicting clause or running the commands apart.

The database engine uses the symbol ER_NOT_ALLOWED_WITH_START_TRANSACTION and SQLSTATE HY000 for this issue. The engine blocks the request before any data changes happen. Knowing why the engine stops the query helps your team keep data safe.

What causes mysql error 3979 in your database

The official message says a start transaction clause cannot be used in your context. MySQL rules block certain modifiers from running at the start of a transaction. This often happens when an app mixes conflicting session rules in one command.

For example, you might mix read and write access modes with snapshot rules. Or a stored program might try to start a transaction inside a restricted block. Database drivers and object mappers can also cause this fault.

Sometimes a client library adds extra flags when it opens a new session. If the driver sends incompatible flags together, the server rejects the whole statement. Cluster routers and pool tools can also inject transaction clauses that clash.

How to find the bad transaction statement

Start by checking your app logs for the exact time of the failure. Look for the SQLSTATE HY000 marker and the number 3979 in the error log. Trace that log entry back to the part of your app that sent it.

Check the settings on your database driver and session pool. Look for any custom startup commands that run when a session begins. Many teams find that a recent code change added a bad transaction flag.

MySQL Access Governance + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

You can also check the server query logs in a test setup. Turn on query logging in a test database and run the failing app action. Read the log to see the exact text the driver sends to MySQL.

How to fix the error safely in production

Once you find the bad command, split the conflicting parts into separate steps. Set your session variables first, and then start the transaction on the next line. Do not combine incompatible access modes in a single start statement.

If an object mapper builds the bad query, update its session setup rules. Make sure it uses standard transaction calls without extra incompatible clauses. Test the fix in a staging setup before you push it to production.

Never fix this issue by giving the app admin rights or turning off checks. Broad permissions will not stop syntax and clause conflicts in the database engine. Keep user roles tight and fix the actual query text instead.

If engineers run manual fixes in production, make sure you mask sensitive fields. Good masking rewrites emails, phone numbers, card numbers, and national IDs in query results. This keeps private data safe while your team fixes the transaction bug.

Inspect every MySQL query and response in flight

Static grants and network rules block bad logins. They cannot pause a risky query for review or mask emails in a result set. By design, hoop.dev sits inline in the MySQL protocol as a sidecar for your MySQL. For every plain query, prepared statement, or cursor an agent or human runs in production, hoop.dev decides to pass, mask, block, or hold it for review.

First, hoop.dev guardrails block banned actions before MySQL runs them, and an AI Analyzer you configure can score intent or escalate for approval. Next, hoop.dev data masking rewrites sensitive string columns in results in memory, and every verdict goes to the audit trail. Find the open-source binary on GitHub.

Frequently asked questions

Does mysql error 3979 corrupt data in my tables?

No, this error happens before the transaction even starts. The database blocks the command right away, so no table data changes.

Why did this error start after a driver update?

New driver versions sometimes change how they start sessions and transactions. Check the release notes of your driver to see if transaction flags changed.

Can I bypass ER_NOT_ALLOWED_WITH_START_TRANSACTION with server settings?

No, you cannot turn off this rule in the server settings. You must fix the statement so it does not use conflicting clauses together.

The query runs. The emails stay hidden.