#!/bin/bash
db_name="zabbix"
mysql_user="root"
mysql_passwd="zabbix"
table_name=`mysql -u$mysql_user -p$mysql_passwd -e "select table_name from information_schema.tables where table_schema='$db_name' and table_type='base table';"|grep -v table_name`
for a in $table_name
do
#列显示
#mysql_char=`mysql -u$mysql_user -p$mysql_passwd -e "select * from $db_name.$a limit 1;"|sed -n "1p"|awk '{for(i=1;i<=NF;i++)print $i}'`
#行显示
mysql_char=`mysql -u$mysql_user -p$mysql_passwd -e "select * from $db_name.$a limit 1;"|sed -n "1p"`
if test -z "$mysql_char"
then
echo "\n$a表为空"
else
echo -e "\n$a 表中的字段\n$mysql_char\n"
fi
done
列显示效果
services 表中的字段
serviceid
name
status
algorithm
triggerid
showsla
goodsla
sortorder
行显示效果
services 表中的字段
serviceid name status algorithm triggerid showsla goodsla sortorder