shell脚本–按格式输出mysql表结构和数据样本

#!/bin/bash

passwd=

database=

mysql -uroot -p$passwd -e "use $database;show tables;" |sed '1系统运维工资一般多少d' > table.txt

for table in `cat table.txt`

do

mysql -mysql数据库命令大全urootmysql数据库 -p$passwd -e "mysqlselect * f系统运维工作内容rom $database.$table t limit 1 \G;" |sed 'shell命令1d' |gawk -F ":" '{print $2}' >table1

mysql -linux系统uroot -p$passwd -e "SELECT COLUMN_NAME "字段名称", COLUMN_TYPE "字段类型长度", COLUMN_系统运维工作内容COMMENT "字段说明" FROM information_sch系统/运维ema.COLUMNS rpt_cap_hour_ammeter_201810 WHERE TABLE_SCHEMA = '$database' AND TABLE_shell脚本NAME = '$table'" |sed '1d' | sed "s/^/$table\t/g" >tmysql数据库命令大全able2

mysql -uroot -p$pamysql索引sswd -e " SELECT TABLE_NAMElinux系统, TABLE_COMMENT FROM information_schema.TABLES WHERE TAmysql数据库命令大全BLE_SCHEMA = '$dlinuxatabase' AND TABLE_NAME = '$tashell编程ble' " |linux重启命令 sed '1d' >table3

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

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

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

for i in `seqlinux操作系统基础知识 1 $num2`

do

num4mysql面试题=`sed -n -e "${i}p" table2|gawk '{print $4}'`

num3=`mysql安装gawk '{print $2}' table3`

if [ "$num4" = "" ]

then

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

echo -linux是什么操作系统n -e "当前字段描shellfish述为空 \t"

else

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

fi

if [ "$num3" = "" ]

then

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

else

echo -nmysql数据库 -e " `gawk '{print $2}' table3` \t "

fi

if [ $num1 == 0 ]

then

echo "空表"

fi

sed -n "${i}p" table1

done

rm -rf table1 tablelinux操作系统基础知识2 table3

echo -e "\nlinux是什么操作系统"

done

rm -rf table.txt

exit