檢視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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 檢視語句執行的時間
- 檢視mysql正在執行的SQL語句MySql
- php連線mysql並執行sql語句PHPMySql
- java連線oracle執行sql語句JavaOracleSQL
- MySQL cron定時執行SQL語句MySql
- 通過日誌檢視mysql正在執行的SQL語句MySql
- mysql sql語句執行超時設定MySql
- 查詢正在執行的sql語句及該語句執行的時間SQL
- oracle 中如何顯示sql語句的執行時間和sql語句的執行後的當前時間OracleSQL
- oracle檢視執行最慢與查詢次數最多的sql語句OracleSQL
- mysql執行sql語句過程MySql
- mysql的sql語句執行流程MySql
- sql server中如何檢視執行效率不高的語句SQLServer
- 檢視當前oracle中正在執行的sql語句OracleSQL
- 【檢視】使用V$SQL_PLAN檢視獲取曾經執行過的SQL語句執行計劃SQL
- SQL語句大全—檢視錶空間(二)SQL
- SQL語句大全—檢視錶空間(一)SQL
- SQL語句執行進度檢查SQL
- 如何實時檢視mysql當前連線數? 薦MySql
- MYSQL 檢視最大連線數和修改最大連線數MySql
- 查詢sql語句執行次數SQL
- mysql如何跟蹤執行的sql語句MySql
- 檢視低效的SQL語句SQL
- 記錄ORACLE語句的執行時間Oracle
- 檢視JVM執行時引數JVM
- MySQL_通過binlog檢視原始SQL語句MySql
- Entity Framework Code First執行SQL語句、檢視及儲存過程FrameworkSQL儲存過程
- MySQL檢視建表語句MySql
- sql語句批量執行SQL
- MySql定位執行效率較低的SQL語句MySql
- Linux 檢視程式啟動時間、執行時間Linux
- 在Linux上檢視活躍執行緒數與連線數Linux執行緒
- MySQL 5.7 檢視理解SQL執行計劃MySql
- [轉]SQL Server 2000定時執行SQL語句SQLServer
- SQL資料庫連線語句SQL資料庫
- 執行sql語句給外部變數賦值SQL變數賦值
- mySQL 執行語句執行順序MySql
- mysql空間大小的SQL語句MySql