4
5

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 2017-10-13

こちらのありがたい記事をみかけて共有したところ流れ(監視につかいたいかなんか)でなんか聞かれたので備忘録です。

設定されてるserver_idの調べ方は以下になります。グローバルに設定されてるサーバ変数はこれで全部いけます。ワイルドカードは%でいけます。

mysql> show global variables like 'server_id';
+---------------+------------+
| Variable_name | Value      |
+---------------+------------+
| server_id     | 1537850619 |
+---------------+------------+
1 row in set (0.00 sec)

ワンラインならこんなかんじ↓

# mysql -u myuser -p -h hoge-rds01 -e "show global variables like 'server_id'\G"|grep -i value|awk -F \: '{print $2}'
1537850619

カレントとマックスの接続数が知りたい場合は以下にあるとおり、です。
http://www.s-quad.com/wordpress/?p=1403

#  mysqladmin -u myuser -p extended-status | egrep '(Max|Threads_)'
| Max_used_connections                       | 3           |
| Threads_connected                          | 2           |
| Threads_created                            | 3           |
| Threads_running                            | 2           |

・同時接続された最大値は、3(Max_used_connections)
・現在接続しているMySQLクライアントは、2(Threads_connected )
・これまでに接続された総数(スレッドキャッシュミスで作られた数)は、3(Threads_created )
・スリープ状態になっていないスレッド数は、2(Threads_running )

ただしこれはステータスであって現在設定されている最大値が知りたいということでしたらば
以下にあるとおりshow global variablesmysqladminVariablesを指定でも見ることができます。

mysql> show global variables like 'max_connections';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 66    |
+-----------------+-------+
1 row in set (0.00 sec)

mysqladmin -u myuser -p -h hoge-rds01 Variables|egrep 'max_connections'

いままでmysqladminでステータスと変数を見ることができることに気付いてなかったのですが、
ステータスがいけるなら変数もいけるであろうと思ってhelpを眺めたらところオプションがありました。

4
5
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
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?