标签:_id password user print style nbsp 获取 eof ram
需求:需要对比所有mysql数据库实例上面的指定参数配置情况,同时需要需要能看到如ip,端口,master or slave,毕竟主和从参数不一样还是有可能的。
说明:必须要有个数据库存储所有是数据库的信息,如ip,端口,主从关系等,我这里恰好都满足,相关敏感信息已脱敏。
#!/bin/bash # #call method:sh script_name @@mysql系统参数1,@@mysql系统参数2...[以逗号分隔每个参数] # #所有数据库实例通用的账号/密码,比如root/root user=root password=root #存储元数据的数据库信息 host=5.5.5.101 port=3306 db=test mysql -u${user} -p${password} -h${host} ${db} 2>/dev/null -Ns > all.txt<<EOF select c.group_name, b.cluster_name, a.db_ip, a.db_port, if(a.is_master = 0, ‘主‘, ‘备‘) from db_node a,db_cluster b,db_cluster_group c where a.cluster_id=b.id and b.group_id=c.id and a.status<>‘deleted‘ order by b.cluster_name; EOF params=$@ cat all |while read line do db_cluster_group=`echo $line | awk ‘{print $1}‘` db_cluster_name=`echo $line | awk ‘{print $2}‘` db_ip=`echo $line | awk ‘{print $3}‘` db_port=`echo $line | awk ‘{print $4}‘` db_role=`echo $line | awk ‘{print $5}‘` mysql -u${user} -p${password} -h$db_ip -P$db_port 2>/dev/null -Nse "select ‘$db_cluster_group‘,‘$db_cluster_name‘,‘$db_ip‘,‘$db_port‘,‘$db_role‘,$params;" done
标签:_id password user print style nbsp 获取 eof ram
原文地址:https://www.cnblogs.com/imdba/p/10115182.html