shell脚本批量检测mysql表中是否存在指定字段
批量查询数据库中表是否存在指定字段,批量添加表字段:
#!/bin/bash
#exit
db_con="/usr/local/mysql/bin/mysql -uroot -p123456"
arr=(db1 db2 db3)
for db in ${arr[*]}
do
${db_con} -e "select count(*) from information_schema.columns where table_schema = '${db}' and table_name = 'table_name' and column_name = 'column_name';" >> /data/shell/test.txt
echo ${db} >> /data/shell/test.txt
#${db_con} -e "ALTER TABLE ${db}.gy_com_customer ADD new_column varchar(100) NOT NULL default '';" 2>/dev/null
echo ${db} " --- done"
done