Common SQL Errors

MySQL Error 1317: ER_QUERY_INTERRUPTED – How to Fix and Prevent

Galaxy Team
August 6, 2025

MySQL raises Error 1317 (ER_QUERY_INTERRUPTED) when the server cancels a running statement, typically after a KILL command, timeout, deadlock, or shutdown.

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL Error 1317 (ER_QUERY_INTERRUPTED)?

MySQL Error 1317: ER_QUERY_INTERRUPTED occurs when the server stops a running statement, usually because of a KILL command, timeout, deadlock, or shutdown. Identify the trigger with SHOW PROCESSLIST, raise max_execution_time or optimize the query, then rerun inside a transaction to solve it.

Error Highlights

Typical Error Message

Query execution was interrupted

Error Type

Query Execution Error

Language

MySQL

Symbol

ER_QUERY_INTERRUPTED

Error Code

1317

SQL State

70100

Explanation

Table of Contents

What is MySQL Error 1317 (ER_QUERY_INTERRUPTED)?

MySQL Error 1317 with SQLSTATE 70100 means the server forcibly stopped a running statement before completion. The official message is "Query execution was interrupted". The interruption can come from a KILL command, timeout, deadlock handling, server shutdown, or resource limits.

The error surfaces at runtime, after parsing succeeds and execution has already begun. Because the server aborts mid-execution, partial data changes may or may not be committed depending on transaction isolation. Fixing the root cause quickly avoids lost work and blocked sessions.

What Causes This Error?

User-initiated KILL QUERY or KILL CONNECTION commands immediately halt the target thread and raise Error 1317. Many GUI tools provide a Stop button that issues the same command.

Long-running statements can exceed the global or session variable max_execution_time, producing an automatic interrupt.

Row-level deadlock resolution may choose the current session as the victim, rolling back the statement and returning ER_QUERY_INTERRUPTED.

Server shutdown, replication failover, or operating-system signals can abort in-flight queries and surface the same error.

Resource exhaustion such as out-of-memory conditions or disk full can trigger an internal interrupt to protect the server.

How to Fix MySQL Error 1317

Identify which mechanism stopped the query by examining the error log, SHOW PROCESSLIST output, and relevant status variables. Confirm whether a human issued a KILL command or an automated timeout fired.

If the query exceeded max_execution_time, increase the limit or optimize the SQL to finish sooner. Index tuning, rewrite of sub-queries, and LIMIT usage usually help.

When deadlock handling is to blame, review InnoDB status to locate conflicting transactions and redesign lock order or add appropriate indexes.

For server shutdown interruptions, restart MySQL and re-run the statement inside a transaction to ensure idempotency.

Common Scenarios and Solutions

Analytics queries scanning huge tables often hit timeouts. Add composite indexes and filter on selective columns to finish within limits.

Background jobs that bulk delete old data may be killed during deploys. Wrap DELETE statements in small batches and resume automatically on failure.

ETL pipelines sometimes clash on the same row set and deadlock. Process tables in consistent order or use SELECT ... FOR UPDATE SKIP LOCKED to avoid waits.

Best Practices to Avoid This Error

Set realistic max_execution_time thresholds per session rather than globally to avoid unintended kills.

Use EXPLAIN and optimizer hints in Galaxy's SQL editor to profile execution plans before running heavy statements in production.

Implement query cancellation hooks in application code so users can safely retry aborted operations.

Monitor information_schema.processlist in Galaxy dashboards and alert when a query nears its timeout.

Related Errors and Solutions

MySQL Error 1205 Lock wait timeout exceeded appears when a query waits too long for a lock rather than being killed outright.

Error 1213 Deadlock found when trying to get lock signals a deadlock that may also pick your session as the victim.

Error 3024 Query exceeded max_execution_time occurs when the optimizer aborts before execution, compared to 1317 which aborts during execution.

Common Causes

KILL QUERY or KILL CONNECTION issued

A user, script, or admin tool explicitly terminated the running statement, immediately raising Error 1317.

Query exceeded max_execution_time

The statement ran longer than the configured time limit, and the server interrupted it automatically.

Deadlock victim selection

InnoDB chose the current session as the deadlock victim and interrupted the query to resolve the cycle.

Server shutdown or failover

A planned or unplanned shutdown ended all active sessions, interrupting in-flight statements.

Resource exhaustion

Out-of-memory, disk full, or similar limits forced MySQL to stop the query for stability.

Related Errors

MySQL Error 1205 lock_wait_timeout

Raised when a statement waits longer than innodb_lock_wait_timeout for a lock to be released.

MySQL Error 1213 deadlock victim

Indicates the server detected a deadlock and rolled back the victim transaction.

MySQL Error 3024 query exceeded max_execution_time

Thrown by the optimizer when the estimated plan surpasses the allowed execution time before it starts running.

FAQs

Does Error 1317 roll back the entire transaction?

If the statement is inside an explicit transaction, MySQL rolls back only that statement. You still need COMMIT or ROLLBACK to finish the rest.

Can I increase the timeout without restarting MySQL?

Yes. Use SET SESSION or GLOBAL max_execution_time to adjust the limit instantly for new statements.

Why do I get Error 1317 during backup?

Dump utilities like mysqldump may be killed by watchdog scripts that terminate long queries. Exclude backup threads from such rules or raise their timeout settings.

How does Galaxy help avoid Error 1317?

Galaxy's SQL editor shows live execution stats and AI-driven query plans so you can optimize or cancel statements before they hit server timeouts.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo