I was reflecting on some early DBA automation scripts I created in bash. This one was targeted to stopping a particular problem the app caused when a piece of Javascript got stuck and sent hundreds – in some cases, over 10,000 – of the same query to the database. It was obviously a temporary fix until dev could roll out a fix.

I called it Little Dutch Boy for obvious reasons. He used his finger to stop a flood? Get it? OK, it amused me. More importantly, it allowed the ops team to not get woken up repeatedly.

pw=`cat /home/valerie/pw`
qp=‘select i.occurrences, i.info from ( select count(info) as occurrences, info from information_schema.processlist where info like “SELECT * FROM schema.table WHERE ( column = ‘%’ ) ORDER BY column2 DESC” group by info ) as i where occurrences>10 limit 1’
mysql -u$us -p$pw -e”$qp” -s -s > /home/valerie/flood_log
id=`tail -n1 /home/valerie/flood_log|awk ‘{print $10}’|awk -F”‘” ‘{print $2}’`
if [ $id ]
          then qi=“select id, user from schema.logins where user=(select user from schema.table where id=$id limit 1)”;
          echo $qi
          #mysql -u$us -p$pw -e”$qi”