美文网首页互联网科技Java 杂谈技术干货
通过shell脚本检测MySQL服务信息

通过shell脚本检测MySQL服务信息

作者: Java黎先生 | 来源:发表于2018-10-07 21:16 被阅读5次

今天改了一版脚本,对于MySQL的基本信息的获取有了一个相对比较清晰的收集方式。

我简单解释下脚本。

整体是分为两部分

第一部分是通过系统层面来解析MySQL的基本信息,方式是通过ps -ef|grep mysql得到的信息来解析。

第二部分是通过登录MySQL得到的信息,基本信息包括server_id,log_bin等。

脚本内容如下:

ps -ef|grep mysql |grep -w mysqld|grep -v grep |awk -F'--' '{for (i=2;i<=NF;i++) {printf $i" "}printf " "}' > info_from_sys.tmp

function get_info_from_sys()

{

while read line

do

array=$line

port_str='port='

socket_str='socket='

for arr_tmp in ${array[*]}; do

if [[ $arr_tmp =~ $port_str ]];then

port_tmp=`echo $arr_tmp|sed 's/port=//g'`

fi

if [[ $arr_tmp =~ $socket_str ]];then

socket_tmp=`echo $arr_tmp|sed 's/socket=//g'`

fi

done

if [ -z "$port_tmp" ];then

port_tmp=3306

fi

echo $port_tmp $socket_tmp >> info_from_sys.lst

done < info_from_sys.tmp

}

function get_info_from_db()

{

while read line

do

port=`echo $line|awk '{print $1}'`

#echo $port

/usr/local/mysql/bin/mysql -udba_admin -p$dec_passwd -h127.0.0.1 -P${port} -N -e "select @@port,@@log_bin,@@innodb_buffer_pool_size,@@gtid_mode,@@datadir,@@character_set_server,@@server_id,version();" >> info_from_db.lst

# echo $port_tmp $socket_tmp

done < info_from_sys.lst

}

function decrypt_passwd

{

tmp_passwd=$1

dec_passwd=`echo $tmp_passwd|base64 -d`

}

##MAIN

get_info_from_sys

sec_password='RHB6TEST1d1c5TTEzZGIwSgo=' --这个是数据库密码的base64加密串,可以根据需求来定制

dec_passwd=''

decrypt_passwd $sec_password

get_info_from_db

sort info_from_db.lst > info_from_db.tmp

sort info_from_sys.lst > info_from_sys.tmp

rm info_from_db.lst info_from_sys.lst

join -j 1 info_from_sys.tmp info_from_db.tmp

最后送波福利。现在加群即可获取Java工程化、高性能及分布式、高性能、高架构。性能调优、Spring,MyBatis,Netty源码分析和大数据等多个知识点高级进阶干货的直播免费学习权限及领取相关资料,群号:835638062 点击链接加入群聊【Java高级架构】:https://jq.qq.com/?_wv=1027&k=5S3kL3v

相关文章

  • 通过shell脚本检测MySQL服务信息

    今天改了一版脚本,对于MySQL的基本信息的获取有了一个相对比较清晰的收集方式。 我简单解释下脚本。 整体是分为两...

  • shell 脚本检测服务运行状态

    由于服务器性能问题,通过shell脚本,定时检测进程运行状态。并自动重启。 一、脚本编辑 check.sh 除此之...

  • Linux shell下载远程文件夹到本地目录

    最近在操作 syno,尝试通过 shell 脚本定时备份远程服务器的项目信息,在此分享下脚本文件。 创建 down...

  • FTP上传文件脚本

    使用shell脚本,通过FTP上传文件到服务器:

  • mysql全量备份数据

    导读:本文介绍的是mysql数据备份恢复的相关知识,以及通过shell编写备份脚本定时执行! 1、mysql数据备...

  • shell中的sql操作

    在编写shell脚本的时候,可能会遇到操作mysql数据库的情况。下面介绍如何在shell脚本中操作mysql数据...

  • Shell脚本检测HTTP服务状态

    编程需求: 在项目有web服务器的时候,监控服务器的状态是非常重要的一项任务,虽然可以通过手动执行命令来进行检测,...

  • systemd服务管理,编写systemd Unit文件

    熟悉systemctl常用命令 通过systemd管理shell脚本 通过systemd管理Nginx服务 熟悉s...

  • PySparkSQL脚本模板

    PySpark模板分为shell脚本和python脚本两部分,通过shell脚本提交spark任务。 shell脚...

  • shell脚本

    备份 MySQL 的 shell 脚本(mysqldump版本) mysql> SET GLOBAL slow_q...

网友评论

    本文标题:通过shell脚本检测MySQL服务信息

    本文链接:https://www.haomeiwen.com/subject/eojraftx.html