MySQL 查看串連數及狀態資訊
一、問題描述
今天營運同事找到我問,有兩台資料庫MYSQL的串連數超過監控的閾值(700),當然他們的監控(zabbix)也是剛剛搭建起來的。表示該值已經從很低的數值一點一點調上來了,但是仍然警示。於是就找到我,做為Oracle’s DBA的我,準備變為雙料DBA,這正是學習的好時機。馬上來學習一下,如何在MYSQL中查詢串連數。
二、實驗
1.show status 查看所有狀態參數,其中Threads_connected 當前的串連數,Connections 試圖串連到(不管是否成功)MYSQL伺服器的串連總數, Max_used_connections 伺服器啟動後已經同時使用過的串連最大數量(並發)。
mysql> show status like '%connect%';
+----------------------+---------+
| Variable_name | Value |
+----------------------+---------+
| Aborted_connects | 163 |
| Connections | 1116123 |
| Max_used_connections | 266 |
| Threads_connected | 208 |
+----------------------+---------+
4 rows in set (0.00 sec)
mysql>
2.show processlist 顯示當前正在執行的mysql串連
mysql> show processlist;
+---------+----------+--------------------+-----------+---------+-------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+---------+----------+--------------------+-----------+---------+-------+-------+------------------+
| 1105357 | tjuser | 10.10.100.30:36210 | testdb | Sleep | 1377 | | NULL |
| 1112435 | tjuser | 10.10.100.30:54112 | testdb | Sleep | 1616 | | NULL |
|…… 略
| 1116128 | tjuser | 10.10.100.21:47484 | testdb | Sleep | 1 | | NULL |
| 1116129 | tjuser | 10.10.100.21:47485 | testdb | Sleep | 64 | | NULL |
+---------+----------+--------------------+-----------+---------+-------+-------+------------------+
207 rows in set (0.00 sec)
3.mysqladmin -u -p -h status 顯示當前mysql狀態
[root@db ~]# mysqladmin -uroot -p -hlocalhost status
Enter password:
Uptime: 14604445 Threads: 208 Questions: 34034734 Slow queries: 179 Opens: 12553 Flush tables: 3 Open tables: 977 Queries per second avg: 2.330
[root@db ~]#
4.mysqladmin -u -p -h extended-status 顯示mysql的其他狀態
[root@db ~]# mysqladmin -uroot -p -hlocalhost extended-status
Enter password:
+------------------------------------------+--------------+
| Variable_name | Value |
+------------------------------------------+--------------+
| Aborted_clients | 53041 |
| Aborted_connects | 163 |
| Connections | 1116157 |
…… 略
| Threads_connected | 206 |
| Threads_created | 633 |
| Threads_running | 1 |
| Uptime | 14604661 |
| Uptime_since_flush_status | 14604661 |
+------------------------------------------+--------------+
[root@db ~]#
三、總結
此次查詢只需要掌握mysql中show status,show process list命令,以及命令mysqladmin。 通過上述命令可以快速得到MYSQL資料庫連接參數與狀態值。查詢到資料庫設定connect數為1000,告訴同事後修改了閾值後正常。
It’s never too late to be what you might have been.
本文永久更新連結地址: