How to Add a ‘STOP ALL SLAVES’ Command to MySQL 5.6 Source Code
This guide walks through extending MySQL 5.6.32 by adding a new SQLCOM_STOP_SLAVES command that stops all replication slaves, detailing modifications to lex.h, sql_cmd.h, sql_yacc.yy, sql_parse.cc, and mysqld.cc, along with compilation tips and troubleshooting steps.
Background
The feature originates from the book Expert MySQL , which describes the internals of MySQL 5.6.x. The goal is to add a new high‑availability command STOP ALL SLAVES that can be issued on the master and propagated to all slaves via the binary log.
Source reference
Original article: https://mysql.az/2016/10/31/playing-with-mysql-source-code-adding-stop-all-slaves-command/
Step‑by‑step source modifications (MySQL 5.6.32)
Update sql/lex.h Add a new token entry for the command, keeping the symbol array alphabetically ordered.
Extend sql/sql_cmd.h Insert a new enum value SQLCOM_STOP_SLAVES into the enum_sql_command list.
Add token to the parser Edit sql/sql_yacc.yy and insert the token SLAVES at the appropriate location (lines 1539‑1540).
Update %type definitions Modify lines 1855‑1856 in sql/sql_yacc.yy to include the new token.
Extend the command list Use the ‘|’ operator to add the new rule in the command list (lines 2079‑2080).
Map token to enum in the parser In sql/sql_parse.cc , add a case that sets the command type to SQLCOM_STOP_SLAVES (lines 8114‑8115).
Write a binlog event Insert logic in sql/sql_parse.cc (lines 3159‑3160) to emit a STOP SLAVE IO_THREAD event when the new command is executed, ensuring the action is replicated.
Register status variable Modify sql/mysqld.cc at lines 3571‑3572 to add the new command to the status‑variable array (replace struct show_var_st with SHOW_VAR ).
Compilation
Build MySQL from source using CMake and Make. For detailed installation steps see https://mysql.az/2015/08/18/installing-mysql-from-source-cmake-issues/. Resolve any compilation errors (e.g., missing my_ok(thd) call) by applying the suggested fix.
Testing
Deploy a master‑two‑slave cluster with MySQL Sandbox. After recompiling, execute STOP ALL SLAVES on the master. The command succeeds and each slave reports the expected stopped state.
Conclusion
By extending the lexical analyzer, command enumeration, YACC grammar, parser switch, binlog writer, and status‑variable registration, the new STOP ALL SLAVES command becomes a first‑class MySQL feature, allowing administrators to halt replication on all slaves with a single statement.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
dbaplus Community
Enterprise-level professional community for Database, BigData, and AIOps. Daily original articles, weekly online tech talks, monthly offline salons, and quarterly XCOPS&DAMS conferences—delivered by industry experts.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
