#!/bin/bash



passwd=

database=




mysql -uroot -p$passwd   -e "use $database;show tables;" |sed '1d' > table.txt

for table in `cat table.txt`

 do

  mysql -uroot -p$passwd   -e "select * from  $database.$table  t limit 1 \G;"  |sed '1d' |gawk -F ":" '{print $2}' >table1

  mysql -uroot -p$passwd   -e "SELECT COLUMN_NAME "字段名称",  COLUMN_TYPE "字段类型长度", COLUMN_COMMENT "字段说明"  FROM  information_schema.COLUMNS  rpt_cap_hour_ammeter_201810 WHERE   TABLE_SCHEMA = '$database'   AND TABLE_NAME = '$table'" |sed '1d' | sed  "s/^/$table\t/g" >table2

 mysql -uroot -p$passwd   -e "   SELECT  TABLE_NAME,   TABLE_COMMENT FROM  information_schema.TABLES  WHERE  TABLE_SCHEMA = '$database'   AND TABLE_NAME = '$table' " |  sed '1d' >table3


#  num3=`awk 'END{print NR}' table3`

  num2=`awk 'END{print NR}' table2`

  num1=`awk 'END{print NR}' table1`


       for  i in `seq 1 $num2`

         do

           num4=`sed -n -e  "${i}p" table2|gawk '{print $4}'`

           num3=`gawk '{print $2}' table3`

          if [ "$num4" = "" ]

           then

            echo  -n -e " `sed -n -e  "${i}p" table2`"

            echo  -n -e "当前字段描述为空 \t"

           else

           echo  -n -e " `sed -n -e  "${i}p" table2` \t"

          fi

          if [  "$num3" =  ""  ]

           then

           echo  -n -e "当前表描述为空 \t "

           else  

           echo -n -e " `gawk '{print $2}' table3` \t "

          fi

             if [ $num1 == 0 ]

              then

               echo "空表"

             fi


           sed -n  "${i}p" table1


         done

 rm -rf table1 table2 table3

  echo -e "\n"


 done

rm -rf table.txt

exit