Common SQL Errors

MySQL Error 3021: ER_SLAVE_CHANNEL_IO_THREAD_MUST_STOP - How to Fix and Prevent

Galaxy Team
August 8, 2025

MySQL blocks replication changes because the channel's IO thread is still running.

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 ER_SLAVE_CHANNEL_IO_THREAD_MUST_STOP (3021)?

MySQL Error 3021 ER_SLAVE_CHANNEL_IO_THREAD_MUST_STOP occurs when you alter replication while the channel's IO thread is active. Stop the thread with STOP SLAVE IO_THREAD FOR CHANNEL 'channel_name', apply your change, then restart replication to resolve the issue.

Error Highlights

Typical Error Message

ER_SLAVE_CHANNEL_IO_THREAD_MUST_STOP

Error Type

Replication Error

Language

MySQL

Symbol

io thread; run STOP SLAVE IO_THREAD FOR CHANNEL '%s' first. ER_SLAVE_CHANNEL_IO_THREAD_MUST_STOP was added in 5.7.6.

Error Code

3021

SQL State

HY000

Explanation

Table of Contents

What is MySQL Error 3021 (ER_SLAVE_CHANNEL_IO_THREAD_MUST_STOP)?

MySQL raises error 3021 ER_SLAVE_CHANNEL_IO_THREAD_MUST_STOP when a replication statement attempts to modify a channel that still has its IO thread running. The server blocks the request to protect replication consistency.

The error appears from MySQL 5.7.6 onward and affects operations such as CHANGE MASTER TO, RESET SLAVE, or channel deletion. Administrators must stop the IO thread first, otherwise the request fails with SQL state HY000.

What Causes This Error?

The primary trigger is an active IO thread on the targeted replica channel. While the thread fetches binary log events, MySQL rejects configuration changes that could corrupt state.

Running START SLAVE or START REPLICA automatically starts the IO thread, so any subsequent CHANGE MASTER TO or RESET SLAVE requires an explicit STOP SLAVE IO_THREAD FOR CHANNEL clause before execution.

How to Fix MySQL Error 3021

Stop the IO thread for the affected channel, rerun the intended replication command, then restart replication. This three-step sequence resolves the error without data loss.

Confirm the IO thread is stopped by checking the Slave_IO_Running column in SHOW SLAVE STATUS or Performance Schema replication_connection_status.

Common Scenarios and Solutions

When re-pointing a replica to a new source, first stop only the IO thread, apply CHANGE MASTER TO, and finally start both threads with START SLAVE.

If you need to purge relay logs, stop the IO thread, issue PURGE BINARY LOGS or RESET SLAVE, then restart replication.

Best Practices to Avoid This Error

Automate replication maintenance scripts to always stop the IO thread before configuration changes. Embed defensive checks that query Slave_IO_Running and exit early if the thread is active.

Adopt channel-specific commands (STOP SLAVE IO_THREAD FOR CHANNEL 'name') in multi-source setups to limit impact on other channels.

Related Errors and Solutions

Error 3022 ER_SLAVE_CHANNEL_SQL_THREAD_MUST_STOP appears when the SQL thread is still running. The fix is analogous: STOP SLAVE SQL_THREAD FOR CHANNEL before altering replication.

Error 3081 ER_BINLOG_UNSAFE_NONTRANS_AFTER_TRANS shows when non-transactional tables are updated after transactional ones in a statement. Use row-based logging or reorder updates.

Common Causes

Active IO thread on the replication channel

START SLAVE or START REPLICA left the IO thread running, so MySQL refuses CHANGE MASTER TO or RESET SLAVE until the thread stops.

Automation scripts lacking safety checks

Maintenance jobs trigger replication changes without first querying Slave_IO_Running, causing the error during busy periods.

Multi-source channel maintenance

Administrators change one channel but forget that its IO thread is fetching events while other channels stay idle, leading to a targeted failure.

Related Errors

ER_SLAVE_CHANNEL_SQL_THREAD_MUST_STOP (3022)

Raised when the SQL thread is active during configuration changes. Stop the SQL thread with STOP SLAVE SQL_THREAD FOR CHANNEL first.

ER_SLAVE_CHANNEL_IO_THREAD_ALREADY_STOPPED (3020)

Occurs when you attempt to stop an IO thread that is already stopped. Verify thread status before issuing STOP SLAVE.

ER_BINLOG_UNSAFE_NONTRANS_AFTER_TRANS (3081)

Indicates unsafe mixed updates in statement-based logging. Switch to row-based logging or reorder statements.

FAQs

Do I need to stop both IO and SQL threads?

Not always. Error 3021 only requires the IO thread to stop, but stopping both threads is safer when making major replication changes.

Will stopping the IO thread cause data loss?

No. The IO thread only fetches events. Stopping it pauses replication but does not drop data or logs.

How do I check if the IO thread is running?

Run SHOW SLAVE STATUS and look at the Slave_IO_Running column. A value of Yes means the thread is active.

Can Galaxy help me avoid this error?

Yes. Galaxy's SQL editor lets you script replication changes with built-in version control, making it easy to include STOP SLAVE commands and share validated procedures with your team.

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