2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MySQLコネクション数確認シェル

Last updated at Posted at 2019-02-08

初投稿します。個人的備忘録に。
時間と、MySQLのコネクション数がファイルに出力される簡単なものです。

connection_count.sh

#!/bin/bash

: >./connection_mysql_count.log #毎回ログファイルを0バイトに

function exe(){

while true
 do
  {
   CONNECT_COUNT=`mysql -h[host_name] -u root -p[password] -e "SHOW PROCESSLIST;" | wc -l`
   echo "connection count:" | awk -v count="$CONNECT_COUNT" '{print strftime("%Y-%m-%d %H:%M:%S"), $0, count}'
   }>> ./connection_mysql_count.log #結果ファイル
   sleep 2 #2秒待つ
 done
}

exe 2>/dev/null #標準エラー出力しない

やめたいときは、「ctrl」 + 「C」でやめて下さい。
同一フォルダに、結果ファイルが出力されます。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?