 {"id":88,"date":"2008-06-24T18:30:16","date_gmt":"2008-06-24T23:30:16","guid":{"rendered":"http:\/\/www.networkjack.info\/blog\/?p=88"},"modified":"2008-12-23T14:53:33","modified_gmt":"2008-12-23T19:53:33","slug":"mysql-replication-slave-control-shell-script","status":"publish","type":"post","link":"http:\/\/www.networkjack.info\/blog\/2008\/06\/24\/mysql-replication-slave-control-shell-script\/","title":{"rendered":"MySQL Replication Slave Control shell script"},"content":{"rendered":"<p>I set up a replication slave at our office to a MySQL server running at our colo and the master server is pretty busy. So busy that even with the compressed protocol option turned on the stream was taking a good 60-70 kbps out of the available bandwidth of our T1. Since it isn&#8217;t critical that this data be real-time slaved, I made a small shell script that can take parameters for starting and stopping either the sql or io threads: mysqlslavectl.sh<\/p>\n<pre>#!\/bin\/sh -\r\n#\r\n#\r\n\r\nUSER=mysqladmin\r\nPASSWD=adminpwd\r\nSCRIPT=\"\/usr\/local\/mysql\/bin\/mysql -u$USER -p$PASSWD -e \"\r\n\r\nStartService ()\r\n{\r\n    case $1 in\r\n      sql  ) $SCRIPT \"START SLAVE SQL_THREAD\"   ;;\r\n      io   ) $SCRIPT \"START SLAVE IO_THREAD\"    ;;\r\n      *      ) echo \"$0: unknown Start argument: $1\";;\r\n    esac\r\n}\r\n\r\nStopService ()\r\n{\r\n    case $1 in\r\n      sql  ) $SCRIPT \"STOP SLAVE SQL_THREAD\"   ;;\r\n      io   ) $SCRIPT \"STOP SLAVE IO_THREAD\"    ;;\r\n      *      ) echo \"$0: unknown Stop argument: $1\";;\r\n    esac\r\n}\r\n\r\nCheckCommand ()\r\n{\r\n    case $1 in\r\n      start  ) StartService \"$2\"   ;;\r\n      stop   ) StopService \"$2\"    ;;\r\n      *      ) echo \"$0: unknown argument: $1\";;\r\n    esac\r\n}\r\n\r\nCheckCommand \"$1\" \"$2\"<\/pre>\n<p>I can call this like so:<\/p>\n<p>mysqlslavectl.sh start io<\/p>\n<p>mysqlslavectl.sh stop sql<\/p>\n<p>I setup a couple of crontab entries, one to start the io thread at 8pm and one to stop the io thread at 6AM.<\/p>\n<p>The sql thread will always be running.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I set up a replication slave at our office to a MySQL server running at our colo and the master server is pretty busy. So&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"http:\/\/www.networkjack.info\/blog\/2008\/06\/24\/mysql-replication-slave-control-shell-script\/\">Continue reading<span class=\"screen-reader-text\">MySQL Replication Slave Control shell script<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,20],"tags":[53,55,51,52,54],"class_list":["post-88","post","type-post","status-publish","format-standard","hentry","category-database","category-mysql","tag-control","tag-cron","tag-replication","tag-slave","tag-thread","entry"],"_links":{"self":[{"href":"http:\/\/www.networkjack.info\/blog\/wp-json\/wp\/v2\/posts\/88"}],"collection":[{"href":"http:\/\/www.networkjack.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.networkjack.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.networkjack.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.networkjack.info\/blog\/wp-json\/wp\/v2\/comments?post=88"}],"version-history":[{"count":2,"href":"http:\/\/www.networkjack.info\/blog\/wp-json\/wp\/v2\/posts\/88\/revisions"}],"predecessor-version":[{"id":152,"href":"http:\/\/www.networkjack.info\/blog\/wp-json\/wp\/v2\/posts\/88\/revisions\/152"}],"wp:attachment":[{"href":"http:\/\/www.networkjack.info\/blog\/wp-json\/wp\/v2\/media?parent=88"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.networkjack.info\/blog\/wp-json\/wp\/v2\/categories?post=88"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.networkjack.info\/blog\/wp-json\/wp\/v2\/tags?post=88"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}