说明:
遍历所有的库表然后查询是否具有主键
/bin/bash
db_host=172.19.211.2 #db ip
db_name_list="chime sso xray intcomm pultus" #填写db_name 支持多个数据库,以空格隔开
for i in $db_name_list;do
table_name_list=`mysql -h$db_host -p'!qaz2Wsx' -e "use $i;show tables;"|egrep -v Tables_` #获取数据库表列表
for j in $table_name_list;do #遍历表
mysql -h$db_host -p'!qaz2Wsx' -e " use $i; SHOW KEYS FROM $j WHERE Key_name = 'PRIMARY';" | grep "PRIMARY" >> /dev/null && echo " [`date "+%Y-%m-%d %H:%M"`] $i.$j is PRIMARY OK !">> PRIMARY_OK.log || echo "[`date "+%Y-%m-%d %H:%M"`] $i.$j ">> not_PRIMARY.log
done
done
标签:-%,name,list,db,PRIMARY,查找,mysql,主键 From: https://www.cnblogs.com/putaoo/p/17027566.html