mysql 测试数据的脚本_Mysql脚本 生成测试数据
Mysql腳本 生成測(cè)試數(shù)據(jù)
使用:
./xie.sh -uroot -p'123456'
#!/bin/bash
#混合測(cè)試數(shù)據(jù)庫(kù)腳本
#將創(chuàng)建一個(gè)single數(shù)據(jù)庫(kù),其中創(chuàng)建一個(gè)s1表
#如果數(shù)據(jù)庫(kù)存在,將會(huì)寫入數(shù)據(jù),可以在寫入部分sleep 1 來(lái)讓數(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:登陸命令錯(cuò)誤"
cat /tmp/info_error.txt #如果錯(cuò)誤則顯示錯(cuò)誤信息
echo
echo "./xx.sh -uroot -p'123456'"
exit 1
fi
#檢查庫(kù)是否存在
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隨機(jī)數(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隨機(jī)數(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脚本 生成测试数据的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: slider获取点击 unity_Uni
- 下一篇: mysql存储过程触发器_【MySQL笔