mysql ----show profile
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了mysql ----show profile,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含7913字,纯文字阅读大概需要12分钟。
内容图文
![mysql ----show profile](/upload/InfoBanner/zyjiaocheng/877/20436301cb144822882f2ca1c1648428.jpg)
show profile:
是mysql提供可以用来分析当前会话中语句执行的资源消耗的情况,可以用于sql的调优的测量。
默认状态下参数处于关闭状态,并保存最近15次的运行结果。
mysql> show variables like '%profil%';
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| have_profiling | YES |
| profiling | OFF |
| profiling_history_size | 15 |
+------------------------+-------+
3 rows in set, 1 warning (0.01 sec)
开关开启后就能拿到最近执行的sql语句了。
mysql> show profiles;
+----------+------------+--------------------------------+
| Query_ID | Duration | Query |
+----------+------------+--------------------------------+
| 1 | 0.05794450 | show variables like '%profil%' |
| 2 | 0.40223375 | select * from stu |
| 3 | 1.00215675 | select sleep(1) |
| 4 | 0.19771625 | show tables |
| 5 | 0.15127925 | select count(*) from employee |
+----------+------------+--------------------------------+
5 rows in set, 1 warning (0.00 sec)
查看执行query 3是cpu 和 io的信息
mysql> show profile cpu ,block io for query 3;
+----------------------+----------+----------+------------+--------------+---------------+
| Status | Duration | CPU_user | CPU_system | Block_ops_in | Block_ops_out |
+----------------------+----------+----------+------------+--------------+---------------+
| starting | 0.000385 | 0.000000 | 0.000000 | NULL | NULL |
| checking permissions | 0.000011 | 0.000000 | 0.000000 | NULL | NULL |
| Opening tables | 0.000039 | 0.000000 | 0.000000 | NULL | NULL |
| init | 0.000013 | 0.000000 | 0.000000 | NULL | NULL |
| optimizing | 0.000016 | 0.000000 | 0.000000 | NULL | NULL |
| executing | 0.000022 | 0.000000 | 0.000000 | NULL | NULL |
| User
| 1.000380 | 0.000000 | 0.000000 | NULL | NULL |
| end | 0.000028 | 0.000000 | 0.000000 | NULL | NULL |
| query end | 0.000014 | 0.000000 | 0.000000 | NULL | NULL |
| closing tables | 0.000008 | 0.000000 | 0.000000 | NULL | NULL |
| freeing items | 0.000204 | 0.000000 | 0.000000 | NULL | NULL |
| logging slow query | 0.000881 | 0.000000 | 0.000000 | NULL | NULL |
| cleaning up | 0.000159 | 0.000000 | 0.000000 | NULL | NULL |
+----------------------+----------+----------+------------+--------------+---------------+
13 rows in set, 1 warning (0.00 sec)
show profile 查看所有信息。
如果在Status结果中出现:以下的信息那么这条sql就有优化的必要。
coverting heap to MyISAM :查询结果太大,内存不够用了。
creating tmp table:创建了临时表
copying to temp table on disk:把内存中的信息赋值到磁盘
locked
mysql> show profile all for query 3;
+----------------------+----------+----------+------------+-------------------+---------------------+--------------+---------------+---------------+-------------------+-------------------+-------------------+-------+--------------------------+----------------------+-------------+
| Status | Duration | CPU_user | CPU_system | Context_voluntary | Context_involuntary | Block_ops_in | Block_ops_out | Messages_sent | Messages_received | Page_faults_major | Page_faults_minor | Swaps | Source_function | Source_file | Source_line |
+----------------------+----------+----------+------------+-------------------+---------------------+--------------+---------------+---------------+-------------------+-------------------+-------------------+-------+--------------------------+----------------------+-------------+
| starting | 0.000385 | 0.000000 | 0.000000 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
| checking permissions | 0.000011 | 0.000000 | 0.000000 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | check_access | sql_authorization.cc | 2202 |
| Opening tables | 0.000039 | 0.000000 | 0.000000 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | open_tables | sql_base.cc | 5587 |
| init | 0.000013 | 0.000000 | 0.000000 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | Sql_cmd_dml::execute | sql_select.cc | 661 |
| optimizing | 0.000016 | 0.000000 | 0.000000 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | JOIN::optimize | sql_optimizer.cc | 213 |
| executing | 0.000022 | 0.000000 | 0.000000 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | JOIN::exec | sql_executor.cc | 228 |
| User sleep | 1.000380 | 0.000000 | 0.000000 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | Item_func_sleep::val_int | item_func.cc | 4989 |
| end | 0.000028 | 0.000000 | 0.000000 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | Sql_cmd_dml::execute | sql_select.cc | 714 |
| query end | 0.000014 | 0.000000 | 0.000000 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | mysql_execute_command | sql_parse.cc | 4520 |
| closing tables | 0.000008 | 0.000000 | 0.000000 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | mysql_execute_command | sql_parse.cc | 4566 |
| freeing items | 0.000204 | 0.000000 | 0.000000 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | mysql_parse | sql_parse.cc | 5237 |
| logging slow query | 0.000881 | 0.000000 | 0.000000 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | log_slow_do | log.cc | 1619 |
| cleaning up | 0.000159 | 0.000000 | 0.000000 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | dispatch_command | sql_parse.cc | 2147 |
内容总结
以上是互联网集市为您收集整理的mysql ----show profile全部内容,希望文章能够帮你解决mysql ----show profile所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。