Error
Error Code:
3021
MySQL Error 3021: Slave IO Thread Running
Description
This error occurs when you attempt to perform an operation on a MySQL replication slave that requires the slave I/O thread to be stopped, but it is currently running. It prevents administrative operations like dropping replication channels or resetting slave status until the I/O thread is explicitly halted.
Error Message
This operation cannot be performed with a running slave io thread; run STOP SLAVE IO_THREAD FOR CHANNEL '%s' first.
Known Causes
4 known causesAttempting Channel Drop
You tried to drop a replication channel using commands like `STOP SLAVE` or `RESET SLAVE` with `FOR CHANNEL` while its IO thread was still active.
Resetting Slave State
An attempt was made to reset the slave's state (e.g., `RESET SLAVE ALL`) when the IO thread for one or more channels was actively running.
Replication Configuration Change
Executing commands to alter or reconfigure replication settings that necessitate a stopped IO thread, without stopping it first.
Unaware Automation Script
An automated script tried to perform an administrative operation on a slave without first checking or stopping the IO thread.
Solutions
3 solutions available1. Stop the Slave IO Thread Immediately easy
Gracefully stop the IO thread to allow the operation.
1
Connect to your MySQL slave server using a MySQL client.
2
Execute the `STOP SLAVE IO_THREAD` command. If you have multiple channels configured, specify the channel name. If not, the default channel is typically used.
STOP SLAVE IO_THREAD FOR CHANNEL 'your_channel_name';
-- Or for the default channel:
STOP SLAVE IO_THREAD;
3
Verify the slave status to confirm the IO thread has stopped. The `Slave_IO_Running` status should be 'No'.
SHOW SLAVE STATUS;
4
Perform your intended operation (e.g., configuration change, restart).
5
Once the operation is complete, restart the slave IO thread.
START SLAVE IO_THREAD FOR CHANNEL 'your_channel_name';
-- Or for the default channel:
START SLAVE IO_THREAD;
2. Restart MySQL Slave Service easy
A quick restart of the MySQL service will reset all threads, including the IO thread.
1
Access your MySQL slave server via SSH or a remote administration tool.
2
Restart the MySQL service. The command varies slightly depending on your operating system.
# For systemd-based systems (e.g., Ubuntu 15.04+, CentOS 7+):
sudo systemctl restart mysql
# For SysVinit-based systems (e.g., older Ubuntu/Debian, CentOS 6):
sudo service mysql restart
# For Windows (using Services manager or PowerShell):
Restart-Service MySQL
3
After the service restarts, the IO thread will be in a stopped state initially. You can then start it if needed.
START SLAVE IO_THREAD;
3. Stop All Replication Threads medium
Stop all replication threads to ensure no replication activity is interfering.
1
Connect to your MySQL slave server.
2
Execute the `STOP SLAVE` command. This will stop both the IO thread and the SQL thread.
STOP SLAVE;
3
Verify that both the IO and SQL threads are stopped by checking the slave status.
SHOW SLAVE STATUS;
4
Perform your intended operation.
5
Restart the slave replication.
START SLAVE;