mysql数据库抓取验收_MySQL 数据库迁移工作小记----连接抓取、展示与异常连接

为了使切换的过程更高效并解放自己的双手,编写了简单的shell脚本,定时抓取连接并存储至核心数据库,简单的例子:#!/bin/bash

StatFile="/var/log/status/processlist.txt"

#获取IP信息

IP=`/sbin/ifconfig | egrep -A 1 "eth[0-4] " | egrep "inet " | egrep -v "192.168|:10."| awk -F‘[ :]+‘ ‘{print $4}‘ | sed -n "1p"`

if [[ $IP = ‘‘ ]]

then

IP=`/sbin/ifconfig | egrep -A 1 "eth[0-4] " | egrep "inet " | egrep  "192.168|:10."| awk -F‘[ :]+‘ ‘{print $4}‘ | sed -n "1p"`

fi

# port.txt 存储端口号

cat /var/log/port.txt | while read port

do

/bin/mysql -h数据库IP -uroot -p‘密码‘ -P$port information_schema -Bse "select ‘$IP‘,‘$port‘,user,substring_index(host,‘:‘,1) as host from  PROCESSLIST where user not in (‘root‘,‘system user‘) group by user,substring_index(host,‘:‘,1);" > $StatFile

# 此处将show processlist信息存入文件,也可直接循环执行

# 将文件中信息存入核心数据库,忽略表结构

cat $StatFile | while read ip  port username host

do

/bin/mysql  -h数据库IP -u用户名  -p 密码’ -P端口  库名 -Bse "insert into mysql_db_proce(db_ip,port,username,app_host) values (‘$IP‘,‘$port‘,‘$username‘,‘$host‘);"

done

done

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值