#!/bin/sh
if [ $# -lt 3 ];then
echo "ERROR: usage: prepare_data.sh {DB_IP} {TABLE_SIZE} {TEST_NAM}"
exit 1
fi
DB_HOST=$1
TABLE_SIZE=$2
test=$3
MYSQL_BIN=mysql
$MYSQL_BIN --help 2>&1 > /dev/null
if [ $? -ne 0 ]; then
if [ -f "/usr/local/mysql/bin/mysql" ]; then
MYSQL_BIN=/usr/local/mysql/bin/mysql
elif [ -f "/usr/bin/mysql" ]; then
MYSQL_BIN=/usr/bin/mysql
fi
fi
ps -ef | grep pd-server | grep -v grep | awk '{print $2}' | xargs kill -9
ps -ef | grep tikv-server | grep -v grep | awk '{print $2}' | xargs kill -9
ps -ef | grep tidb-server | grep -v grep | awk '{print $2}' | xargs kill -9
unset http_proxy
unset https_proxy
sed -i "s/^mysql-host=.*/mysql-host=${DB_HOST}/g" config
sed -i "s/^IP_CONFIG=.*/IP_CONFIG=${DB_HOST}/g" start_tidb.sh
sh start_tidb.sh
sleep 60
$MYSQL_BIN -h $DB_HOST -P 4000 -u root -D sbtest \
-Be "DROP DATABASE sbtest;"
$MYSQL_BIN -h $DB_HOST -P 4000 -u root -Be "create database sbtest;"
sysbench --config-file=config $test \
--tables=32 --table-size=$TABLE_SIZE --time=30 prepare