user_name=root
user_password=123456
ip_address=localhost
database_name=jobgrid
table_name=z_mzm
column_name=*
char_set=utf8
display_type=-l
limit=10
for i in $@
do
[ `echo $i | cut -c 2` = "u" ] && user_name=`echo $i | cut -c 3-`
[ `echo $i | cut -c 2` = "p" ] && user_password=`echo $i | cut -c 3-`
[ `echo $i | cut -c 2` = "h" ] && ip_address=`echo $i | cut -c 3-`
[ `echo $i | cut -c 2` = "d" ] && database_name=`echo $i | cut -c 3-`
[ `echo $i | cut -c 2` = "t" ] && table_name=`echo $i | cut -c 3-`
[ `echo $i | cut -c 2` = "c" ] && column_name=`echo $i | cut -c 3-`
[ `echo $i | cut -c 2` = "s" ] && char_set=`echo $i | cut -c 3-`
[ `echo $i | cut -c 2` = "l" ] && limit=`echo $i | cut -c 3-`
if [ `echo $i | cut -c 2` = "e" ]
then
explorer=epiphany
display_type=-ht
[ `echo $i | cut -c 3` = "f" ] && explorer=firefox
[ `echo $i | cut -c 3` = "k" ] && explorer=konqueror
fi
done
if [ $limit = "all" ]
then
# -lall即全部选择
limit=""
else
# 默认情况下只选择前10条数据
limit="limit $limit"
fi
title=`mysql -u$user_name -p$user_password -h$ip_address --default-character-set=$char_set -e"use $database_name; desc $table_name" | awk '{if (NR != 1) printf "%s,", $1}'`
if [ "`echo "${column_name}" | cut -c 1`" = "*" ]
then
# 如果column_name=*,则从数据库得到元数据作为要显示的列名
title=-ti=$title
else
# 如果column_name已经指定,则从指定的名称得到要显示的列名
title=-ti=$column_name
fi
if [ $display_type = "-l" ]
then
mysql -u$user_name -p$user_password -h$ip_address --default-character-set=$char_set -e"use $database_name; select $column_name from $table_name $limit" | sed '1d' | showtable $title $display_type
else
file_name=/tmp/table.html
mysql -u$user_name -p$user_password -h$ip_address --default-character-set=$char_set -e"use $database_name; select $column_name from $table_name $limit" | sed '1d' | showtable $title $display_type > $file_name
$explorer $file_name&
fi
先试一下你的系统有没有showtable这个命令,如果有的话,假设上述文件名为select,用法如下:
select
select -ef
select -l100
select -lall
select -cMZM,MZM_CONTENT
等等