`
garyli
  • 浏览: 173108 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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 !"

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics