Skip to content

Instantly share code, notes, and snippets.

@mikeadmire
Created June 1, 2016 02:05
Show Gist options
  • Save mikeadmire/3dc692e0bef615a5c05f8edebccbeae0 to your computer and use it in GitHub Desktop.
Save mikeadmire/3dc692e0bef615a5c05f8edebccbeae0 to your computer and use it in GitHub Desktop.
Script to run against RDS slave to skip 1045 errors and restart replication if it stops.
#!/usr/bin/env ruby
require 'mysql2'
while 1
client = Mysql2::Client.new(
host: "",
username: "",
password: "")
slave_status = client.query("show slave status;")
if slave_status.first["Last_SQL_Errno"] == 1045
client.query("CALL mysql.rds_skip_repl_error;")
elsif slave_status.first["Slave_IO_Running"] == "No"
client.query("CALL mysql.rds_start_replication;")
end
sleep 0.5
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment