shell 写的数据库查询工具

#!/bin/sh
echo "********************************************************"
echo "  1. Describe all table construct."
echo "  2. Show a Table's content by you input table name."
echo "  3. Show a Case's info by you input case id."
echo "*********************************************************"
echo "please select a number (1 ~ 3):"
read answer

if [ $answer -eq 1 ];
then
	tables=`mysql -u root -e "use i_test;show tables;"`

	for list in $tables
	do
		if [ $list == 'Tables_in_i_test' ];
		then
			echo "Table in i_test:" >> a.txt
		else
			echo >>a.txt
			echo TABLE "["$list"]" DESCRIBE:>>a.txt
			mysql -u root -t -e"desc i_test.$list" |tee -a a.txt
		fi
	done
elif [ $answer -eq 2 ];
then 
	echo "please input a table name:"
	read tbname
	mysql -u root -t -e"select * from i_test.$tbname"|tee -a select.txt
elif [ $answer -eq 3 ]; 
then 
        echo "please input a case_id:"
        read case_id
		tables=`mysql -u root -e "use i_test;show tables;"`
		for table in $tables
		do
			if [ $table != 'Tables_in_i_test' ]
			then
				have=`mysql -u root -e"desc i_test.$table case_id"`
				have="$have"
				if [ "$have" != "" ];
				then
					echo $table >>cases_info.txt
					mysql -u root -t -e "use i_test;select * from $table where case_id =$case_id"|tee -a cases_info.txt
				fi
			fi
		done
fi

echo " The Shell is Complate !"

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值