为了模拟不断插入数据到库里,写个简单的循环脚本
#!/bin/bash
#计算时差
function getTiming(){start=$1end=$2start_s=`echo $start | cut -d '.' -f 1`start_ns=`echo $start | cut -d '.' -f 2`end_s=`echo $end | cut -d '.' -f 1`end_ns=`echo $end | cut -d '.' -f 2`time_micro=$(( (10#$end_s-10#$start_s)*1000000 + (10#$end_ns/1000 - 10#$start_ns/1000) ))time_ms=`expr $time_micro/1000 | bc `#echo "$time_micro microseconds"echo "$time_ms ms"
}#不断插入
while true
dolog="/tmp/ins_`date +%Y%m%d%H`.log"start_time=`date +%s.%N`mysql -h127.0.0.1 -uroot -P3306 -p'123' -Dtest -N -e"insert into temp1(seq_no, client, beasts,tran_date) values (concat('test1_',cast (md5(rand()) as string)),'cow', 'horse' ,now());commit;select count(0) from temp1;select now()" >> $logend_time=`date +%s.%N`getTiming $start_time $end_timesleep $1
done
执行效果:
0.2是每次插入后延时0.2秒
日志输出:
仅为验证数据插入是否报错或有明显的变慢情况。