檢視mysql連線數 sql語句執行時間
檢視mysql連線數
1 ./mysqladmin -uroot -p123456 -h192.168.9.172 processlist
可以檢視具體詳細資訊
[root@sznagios bin]# pwd
/usr/bin
[root@nagios bin]# ./mysqladmin -uroot -p123456 -h192.168.9.172 processlist
+--------+-----------+---------------------+-----------------+---------+-------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+--------+-----------+---------------------+-----------------+---------+-------+-------+------------------+
| 27 | centreon | 192.168.9.172:47700 | centreon_status | Sleep | 0 | | |
| 78 | cactiuser | localhost | syslog | Sleep | 55 | | |
+--------+-----------+---------------------+-----------------+---------+-------+-------+------------------+
或者 進入mysql也可以檢視:
mysql> show full processlist;
+-------+-----------+---------------------+------------------+---------+-------+-------+-----------------------+
| Id | User | Host | db | Command | Time | State | Info |
+-------+-----------+---------------------+------------------+---------+-------+-------+-----------------------+
| 15 | cactiuser | localhost | syslog | Sleep | 0 | | NULL |
| 225 | centreon | localhost | centreon_status | Sleep | 1 | | NULL |
| 76778 | root | 172.16.200.53:54830 | NULL | Sleep | 15344 | | NULL |
| 76779 | root | 172.16.200.53:54831 | centreon_storage | Sleep | 15342 | | NULL |
| 76789 | root | 172.16.200.53:54841 | centreon_storage | Sleep | 15322 | | NULL |
| 76790 | root | 172.16.200.53:54843 | centreon_storage | Sleep | 15317 | | NULL |
| 84523 | root | localhost | NULL | Query | 0 | NULL | show full processlist |
+-------+-----------+---------------------+------------------+---------+-------+-------+-----------------------+
7 rows in set (0.00 sec)
2 ./mysqladmin -ucentreon -p123456 -h172.25.128.35 status
可以檢視總數 (Threads就是連線數)
[root@sznagios bin]# ./mysqladmin -ucentreon -p123456 -h192.168.9.172 status
Uptime: 57809 Threads: 76 Questions: 19264613 Slow queries: 33 Opens: 39310 Flush tables: 1 Open tables: 64 Queries per second avg: 333.245
3 sql語句執行時間
3.1 profiles方法
預設profiles不開啟
mysql> show profiles;
Empty set (0.00 sec)
mysql> show variables like "%pro%";
+---------------------------+-------+
| Variable_name | Value |
+---------------------------+-------+
| profiling | OFF |
| profiling_history_size | 15 |
| protocol_version | 10 |
| slave_compressed_protocol | OFF |
+---------------------------+-------+
4 rows in set (0.00 sec)
開啟profiles
mysql> set profiling=1;
Query OK, 0 rows affected (0.00 sec)
mysql> use mysql;
Database changed
mysql> select * from user;
+-----------------------+-----------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+-------
mysql> show profiles;
+----------+------------+--------------------+
| Query_ID | Duration | Query |
+----------+------------+--------------------+
| 1 | 0.00020300 | SELECT DATABASE() |
| 2 | 0.00067100 | select * from user |
+----------+------------+--------------------+
2 rows in set (0.00 sec)
3.2 timestampdiff來檢視測試時間
mysql> set @d=now();
Query OK, 0 rows affected (0.00 sec)
mysql> select * from user;
+-----------------------+-----------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------
mysql> select timestampdiff(second,@d,now());
+--------------------------------+
| timestampdiff(second,@d,now()) |
+--------------------------------+
| 39 |
+--------------------------------+
1 row in set (0.00 sec)
注意:三條sql語句要儘量連一起執行,不然誤差太大
1 ./mysqladmin -uroot -p123456 -h192.168.9.172 processlist
可以檢視具體詳細資訊
[root@sznagios bin]# pwd
/usr/bin
[root@nagios bin]# ./mysqladmin -uroot -p123456 -h192.168.9.172 processlist
+--------+-----------+---------------------+-----------------+---------+-------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+--------+-----------+---------------------+-----------------+---------+-------+-------+------------------+
| 27 | centreon | 192.168.9.172:47700 | centreon_status | Sleep | 0 | | |
| 78 | cactiuser | localhost | syslog | Sleep | 55 | | |
+--------+-----------+---------------------+-----------------+---------+-------+-------+------------------+
或者 進入mysql也可以檢視:
mysql> show full processlist;
+-------+-----------+---------------------+------------------+---------+-------+-------+-----------------------+
| Id | User | Host | db | Command | Time | State | Info |
+-------+-----------+---------------------+------------------+---------+-------+-------+-----------------------+
| 15 | cactiuser | localhost | syslog | Sleep | 0 | | NULL |
| 225 | centreon | localhost | centreon_status | Sleep | 1 | | NULL |
| 76778 | root | 172.16.200.53:54830 | NULL | Sleep | 15344 | | NULL |
| 76779 | root | 172.16.200.53:54831 | centreon_storage | Sleep | 15342 | | NULL |
| 76789 | root | 172.16.200.53:54841 | centreon_storage | Sleep | 15322 | | NULL |
| 76790 | root | 172.16.200.53:54843 | centreon_storage | Sleep | 15317 | | NULL |
| 84523 | root | localhost | NULL | Query | 0 | NULL | show full processlist |
+-------+-----------+---------------------+------------------+---------+-------+-------+-----------------------+
7 rows in set (0.00 sec)
2 ./mysqladmin -ucentreon -p123456 -h172.25.128.35 status
可以檢視總數 (Threads就是連線數)
[root@sznagios bin]# ./mysqladmin -ucentreon -p123456 -h192.168.9.172 status
Uptime: 57809 Threads: 76 Questions: 19264613 Slow queries: 33 Opens: 39310 Flush tables: 1 Open tables: 64 Queries per second avg: 333.245
3 sql語句執行時間
3.1 profiles方法
預設profiles不開啟
mysql> show profiles;
Empty set (0.00 sec)
mysql> show variables like "%pro%";
+---------------------------+-------+
| Variable_name | Value |
+---------------------------+-------+
| profiling | OFF |
| profiling_history_size | 15 |
| protocol_version | 10 |
| slave_compressed_protocol | OFF |
+---------------------------+-------+
4 rows in set (0.00 sec)
開啟profiles
mysql> set profiling=1;
Query OK, 0 rows affected (0.00 sec)
mysql> use mysql;
Database changed
mysql> select * from user;
+-----------------------+-----------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+-------
mysql> show profiles;
+----------+------------+--------------------+
| Query_ID | Duration | Query |
+----------+------------+--------------------+
| 1 | 0.00020300 | SELECT DATABASE() |
| 2 | 0.00067100 | select * from user |
+----------+------------+--------------------+
2 rows in set (0.00 sec)
mysql> set @d=now();
Query OK, 0 rows affected (0.00 sec)
mysql> select * from user;
+-----------------------+-----------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------
mysql> select timestampdiff(second,@d,now());
+--------------------------------+
| timestampdiff(second,@d,now()) |
+--------------------------------+
| 39 |
+--------------------------------+
1 row in set (0.00 sec)
注意:三條sql語句要儘量連一起執行,不然誤差太大
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29734436/viewspace-1280689/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- java連線oracle執行sql語句JavaOracleSQL
- MySQL cron定時執行SQL語句MySql
- mysql sql語句執行超時設定MySql
- mysql的sql語句執行流程MySql
- mysql執行sql語句過程MySql
- [20190125]簡單快速檢視那些sql語句正在執行.txtSQL
- MySQL_通過binlog檢視原始SQL語句MySql
- MySQL檢視建表語句MySql
- Linux 檢視程式啟動時間、執行時間Linux
- SQL語句執行順序SQL
- sql語句如何執行的SQL
- 一條SQL語句在MySQL中如何執行的MySql
- T-SQL運維指令碼——檢視SQLServer平均最耗資源時間的SQL語句SQL運維指令碼Server
- mySQL 執行語句執行順序MySql
- 在Linux上檢視活躍執行緒數與連線數Linux執行緒
- 檢視JVM執行時引數JVM
- 執行一條 SQL 語句,期間發生了什麼?SQL
- sql 語句網路除錯和 sql 語句低層傳輸檢視SQL除錯
- MySQL探祕(二):SQL語句執行過程詳解MySql
- 一條sql語句在mysql中是如何執行的MySql
- 一條 SQL 語句在 MySQL 中是如何執行的?MySql
- sql語句執行緩慢分析SQL
- SQL 語句的執行順序SQL
- 後臺執行SQL語句(oracle)SQLOracle
- Mybatis 動態執行SQL語句MyBatisSQL
- 什麼是 MySQL JDBC 連線池中最高效的連線檢測語句?MySqlJDBC
- MySQL語句執行分析(一)MySql
- MySQL語句執行分析(二)MySql
- MySQL內連線查詢語句MySql
- 檢視mysql執行狀態的一些sqlMySql
- 一個 MySQL sql 語句執行順序帶來的 bugMySql
- MySQL日誌(一條sql更新語句是如何執行的)MySql
- MySQL 記錄所有執行了的 sql 語句MySql
- Laravel 獲取執行的sql語句LaravelSQL
- mysql 語句的執行順序MySql
- 當執行一條select語句時,MySQL到底做了啥?MySql
- MySQL系列之一條SQL查詢語句的執行過程MySql
- DM7聯機執行SQL語句進行表空間備份SQL
- oracle查詢sql執行耗時、執行時間、sql_idOracleSQL