If there are less than 10 databases, You can manually enter ssh, and clean is enough. But if there are hundreds of databases, you have to write scripts. General idea: On a db jump machine, write a script to access slave, remotely obtain the binlog location on the master that is being copied, and then remotely Go To The binlog on the purge master.
1. Create the slave dbserver list slavelist; one slave row.
2. Remotely obtain the binlog location on the slave db and the master Host Name (maybe IP address) of the slave)
3. Get the binlog location and master host name, and then remotely clear the binlog on the master using ssh.
4. shell for loop operation steps 2 and 3.
Script 1: clean_binlog.sh Copy codeThe Code is as follows :#! /Bin/bash
# P1 the slave mysql db server
Db03 = $1
Echo $ dbserver;
Ster_Log_File = 'ssh $ db03 "mysql-uxx-pxx -- ssl-ca =/opt/mysql/ssl/ca-cert.pem -- s
Sl-cert =/opt/mysql/ssl/server-cert.pem -- ssl-key =/opt/mysql/ssl/server-key.pem-e \ "show slave status \ G; \ "| grep-I master_Log_File
"';
# Echo ##### obtain binlog Information
Log_file = 'echo $ ster_Log_File | awk '{print $2 }'';
Db01tmp = 'ssh $ db03 "mysql-uxx-pxx -- ssl-ca =/opt/mysql/ssl/ca-cert.pem -- s
Sl-cert =/opt/mysql/ssl/server-cert.pem -- ssl-key =/opt/mysql/ssl/server-key.pem-e \ "show slave status \ G; \ "| grep-I Master_Host
"';
Copy codeThe Code is as follows: # obtain the master host name or IP address
Db01 = 'echo $ db01tmp | awk '{print $2 }''
# Start clearing binlog Information
Copy codeThe Code is as follows: ssh $ db01 "mysql-uxxx-pxx -- ssl-ca =/opt/mysql/ssl/ca-cert.pem -- ssl-cert =/op
T/mysql/ssl/server-cert.pem -- ssl-key =/opt/mysql/ssl/server-key.pem-e \ "purge master logs to '$ log_file ';\""
# Check the binlog information on the master
Copy codeThe Code is as follows: ssh $ db01 "df-h/mysql/binlog ";
Copy codeThe Code is as follows: <STRONG> <SPAN style = "COLOR: # ff0000"> </SPAN> </STRONG>
With batch for loop Script 2:
For s in 'cat slavelist'; do sh clean_binlog.sh $ s; done
This is a rough solution, and there must be some shortcomings. My 128 group is a mm combination, so this operation is acceptable, and there will be changes in different architectures, this also involves the binlog backup before purge (with dedicated backup machines and backup scripts ).