Created
August 15, 2013 09:19
-
-
Save gb-swatanabe/6239511 to your computer and use it in GitHub Desktop.
一定間隔でテーブル更新を行う(レプリケーション構成での障害試験などを想定
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
MYSQL_USER=root # mysql user | |
MYSQL_PWD=******** # mysql password | |
INTERVAL=1 # update interval (sec.) | |
export MYSQL_PWD | |
dbname=test_db | |
table=test_table | |
case "$1" in | |
"init") | |
# initializing | |
mysqladmin -u$MYSQL_USER -f drop $dbname | |
mysqladmin -u$MYSQL_USER create $dbname | |
mysql -u$MYSQL_USER -e "CREATE TABLE $table (id INT NOT NULL PRIMARY KEY, cnt INT NOT NULL);" $dbname | |
mysql -u$MYSQL_USER -e "INSERT INTO $table VALUES ( 1, 0 );" $dbname | |
echo "initializind test db finished." | |
mysql -u$MYSQL_USER -e "SELECT * FROM $table WHERE id = 1;" $dbname | |
;; | |
"run") | |
# infinity loop | |
while : | |
do | |
mysql -u$MYSQL_USER -e "UPDATE $table SET cnt=cnt+1 WHERE id = 1;" $dbname | |
printf "%s : %d\n" "$( date )" $( mysql -B -s -r -u$MYSQL_USER -e "SELECT cnt FROM $table WHERE id = 1" $dbname ) | |
sleep $INTERVAL | |
done | |
;; | |
"show") | |
mysql -u$MYSQL_USER -e "SELECT * FROM $table WHERE id = 1;" $dbname | |
;; | |
*) | |
# help message | |
prog=$( basename $0 ) | |
printf "usage: %s init .... initialize test db and table.\n" $prog | |
printf " %s run ..... update test table (interval: %d sec).\n" $prog $INTERVAL | |
printf " %s show .... show now table contents.\n" $prog | |
echo | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment