sql性能分析器

查询是否开启性能分析器
mysql> select @@profiling;
+-------------+
| @@profiling |
+-------------+
|           1 |
+-------------+
1 row in set (0.00 sec)


开启性能分析器
mysql> set global profiling=1;
Query OK, 0 rows affected (0.00 sec)

查询你之前查询过的语句
mysql> show profiles;
+----------+------------+--------------------------------------------+
| Query_ID | Duration   | Query                                      |
+----------+------------+--------------------------------------------+
|        1 | 0.00010550 | select @@version_comment limit 1           |
|        2 | 0.00009900 | select @@profiling                         |
|        3 | 0.00038875 | select User,Host,Password from mysql.mysql |
|        4 | 0.00065050 | select User,Host,Password from mysql.user  |
|        5 | 0.00008325 | select @@profiling                         |
|        6 | 0.00008600 | set global profiling=1                     |
+----------+------------+--------------------------------------------+

分析你之前查询过的语句
mysql> show profile for query 6;
+--------------------+----------+
| Status             | Duration |
+--------------------+----------+
| starting           | 0.000037 |
| Opening tables     | 0.000008 |
| query end          | 0.000002 |
| closing tables     | 0.000002 |
| freeing items      | 0.000036 |
| logging slow query | 0.000001 |
| cleaning up        | 0.000001 |
+--------------------+----------+
7 rows in set (0.00 sec)

SQL 性能分析器可以帮助我们对一些比较难以确定性能问题的 SQL 进行诊断,找出问题根源。
用explain看看是否用到索引

mysql> explain select User,Host,Password from mysql.user\G
*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: user
         type: ALL
possible_keys: NULL
          key: NULL
      key_len: NULL
          ref: NULL
         rows: 3
        Extra:
1 row in set (0.00 sec)
mysql>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值