mysql 测试数据的脚本_Mysql脚本 生成测试数据
Mysql腳本 生成測試數(shù)據(jù)
使用:
./xie.sh -uroot -p'123456'
#!/bin/bash
#混合測試數(shù)據(jù)庫腳本
#將創(chuàng)建一個single數(shù)據(jù)庫,其中創(chuàng)建一個s1表
#如果數(shù)據(jù)庫存在,將會寫入數(shù)據(jù),可以在寫入部分sleep 1 來讓數(shù)據(jù)持續(xù)寫入
#使用方法 ./xx.sh -uroot -p'123456'
#檢查
mysql $* -e "show databases;" &> /tmp/info_error.txt
if [[ $? -ne 0 ]];then
echo "time:$(date +%F-%H-%M-%S) info:登陸命令錯誤"
cat /tmp/info_error.txt #如果錯誤則顯示錯誤信息
echo
echo "./xx.sh -uroot -p'123456'"
exit 1
fi
#檢查庫是否存在
mysql $* -e "use single;" &> /tmp/info_error.txt
if [[ $? -eq 0 ]];then
mysql $* -e "use single;select * from s1 where id=1;"
if [[ $? -ne 0 ]];then
mysql $* -e "use single;drop table s1;"
mysql $* -e "use single;create table s1(id int AUTO_INCREMENT PRIMARY KEY,name char(20),age int);"
fi
else
mysql $* -e "create database single;"
mysql $* -e "use single;create table s1(id int AUTO_INCREMENT PRIMARY KEY,name char(20),age int);"
fi
#name隨機數(shù)
random_name() {
local zu=(q w e r t y u i o p a s d f g h j k l z x c v b n m)
for i in `seq 1 5`
do
local a=`echo $[RANDOM%24]`
echo -n ${zu[a]}
done
}
#age隨機數(shù)
random_age() {
local a=`echo $[RANDOM%99]`
echo $a
}
#寫入部分
for i in `seq 1 10000`
do
b=`random_name`
c=`random_age`
sleep 2
mysql $* -e "use single;insert into s1(name,age) values('${b}',${c});"
done
總結(jié)
以上是生活随笔為你收集整理的mysql 测试数据的脚本_Mysql脚本 生成测试数据的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: slider获取点击 unity_Uni
- 下一篇: linux cmake编译源码,linu