Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> MySQL

ดูสถานะ Connection ใน MySQL (Active/Total Connections)

ใช้ SHOW STATUS ตัวแปร Threads_connected และ SHOW PROCESSLIST

ดู Active Connections

mysql> SHOW STATUS WHERE Variable_name = 'Threads_connected';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| Threads_connected | 1     |
+-------------------+-------+

ดู Process List รายละเอียด

mysql> SHOW PROCESSLIST;
+----+-----------------+-----------------+----------+---------+--------+------------------------+------------------+
| Id | User            | Host            | db       | Command | Time   | State                  | Info             |
+----+-----------------+-----------------+----------+---------+--------+------------------------+------------------+
| 4  | event_scheduler | localhost       | NULL     | Daemon  | 349012 | Waiting on empty queue | NULL             |
| 11 | root            | localhost:54746 | business | Query   | 1      | starting               | show processlist |
+----+-----------------+-----------------+----------+---------+--------+------------------------+------------------+

ตัวแปร Status ที่เกี่ยวข้อง

Variableความหมาย
Threads_connectedConnection ที่เปิดอยู่ตอนนี้ (Active)
Threads_runningConnection ที่กำลัง Execute Query (ไม่รวม Sleep)
ConnectionsConnection ทั้งหมดนับตั้งแต่ Start Server (Cumulative)
Max_used_connectionsPeak Concurrent Connections
Aborted_connectsConnection ที่พยายามเชื่อมแต่ Failed

Query ดูทั้งหมดพร้อมกัน

SHOW GLOBAL STATUS WHERE Variable_name IN 
('Threads_connected', 'Threads_running', 'Connections', 'Max_used_connections', 'Aborted_connects');
Monitoring: ตั้ง Alert เมื่อ Threads_connected ใกล้ max_connections (Default 151) และดู Threads_running สำหรับ Load จริง