RDSのリードレプリカ作成後にテーブルデータをプリロードする
レプリカ作成した後、全テーブルをプライマリキーで検索してテーブルデータをメモリにロードしておきます。
#!/bin/sh stage=$1 stty -echo echo -n "password for ${stage} ?> " read pass stty echo SLAVE="${stage}-db-slave-1.xxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com" USER="user" DB="db_${stage}" OPTS="-u${USER} -p${pass} -h ${stage}-db-master-1 $MYSQLOPTS" MYSQLSHOW="mysqlshow $OPTS" tables=$($MYSQLSHOW $DB | cut -d "|" -f 2 | sed "s/^ //g" | grep -v "^Name" | grep -v "^Database: " | grep -v "^\+---" | sed -e "1d") for table in $tables; do echo "$table" mysql -u${USER} -h ${SLAVE} -p${pass} ${DB} -e "select count(*) from ${table} where id between 1 and (select max(id) from ${table});" done exit 0