For us, the answer DELETE WHERE %s ORDER BY %s LIMIT %d not an option, because the WHERE criteria were slow (an unindexed column) and would fall into master.
Select from read-replica the list of primary keys that you want to delete. Export with this format:
00669163-4514-4B50-B6E9-50BA232CA5EB 00679DE5-7659-4CD4-A919-6426A2831F35
Use the following bash script to capture this input and put it in DELETE statements [bash ≥ 4 required due to the built-in mapfile ]:
sql-chunker.sh (remember chmod +x me and change shebang to point to your bash 4 executable):
Call like this:
./sql-chunker.sh 1000 ids.txt > batch_1000.sql
This will give you a file with output formatting (I used batch size 2):
DELETE FROM my_cool_table WHERE id IN ('006CC671-655A-432E-9164-D3C64191EDCE','006CD163-794A-4C3E-8206-D05D1A5EE01E'); DELETE FROM my_cool_table WHERE id IN ('006CD837-F1AD-4CCA-82A4-74356580CEBC','006CDA35-F132-4F2C-8054-0F1D6709388A');
Then follow these steps:
mysql --login-path=master billing < batch_1000.sql
For those who are not familiar with login-path , this is just a shortcut to enter the system without entering a password on the command line.
Birchlabs Nov 29 '17 at 15:08 2017-11-29 15:08
source share