MySQL のコネクション数を調べる
サービスの拡大に伴い、MySQLへのコネクション数も増えていくものです。
Too many connections が出たら
出ました。(アプリケーション側のエラーログから検知)
SQLSTATE[08004] [1040] Too many connections
現状確認
mysql> show variables like 'max_connections'; +-----------------+-------+ | Variable_name | Value | +-----------------+-------+ | max_connections | 1200 | +-----------------+-------+ 1 row in set (0.00 sec)
(ノ∀`)アチャー
mysql> show status like 'Max_used_connections'; +----------------------+-------+ | Variable_name | Value | +----------------------+-------+ | Max_used_connections | 1201 | +----------------------+-------+ 1 row in set (0.00 sec)
超えてる…
現在の接続数
mysql> show status like 'Threads_connected'; +-------------------+-------+ | Variable_name | Value | +-------------------+-------+ | Threads_connected | 47 | +-------------------+-------+ 1 row in set (0.00 sec)
応急処置
とりあえず上げます
set global max_connections = 1250;
/etc/my.cnf も忘れずに
max_connections = 1250
対策
このままだとイタチごっこですので、どの時間帯にどのホストからのコネクション数が多いのか見れるようにしていこうと思います。