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
热度:86 发布时间:2024-01-27 03:48:35.0
相关解决方案
- mysql 简单化 or能否实现
- 请问registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister
- MySQL 5.5 Command Line Client 窗口1输密码就退出
- 在LINUX上配置 MySQL 开机自动 启动
- mysql 转 orocle java ssh项目一条 sql 句不通!
- 上了个 MySQL 5.5.25 但是安装时出错了
- JDBC MYSQL 驱动加载失败 JSP DAO ECLIPSE,该怎么解决
- tomcat 中抛异com.mysql.jdbc.exceptions.MySQLTransactionRollbackException,该如何处理
- struts+iBatis+mysql,该如何解决
- mysql 有外键的插入解决方案
- mysql,该如何处理
- 问一个httpconnection.setRequestProperty("User-Agent" "Profile/MIDP-1.0 Configuration/CLDC-1.0");的有关问题
- 编译PBP遇到的有关问题(Personal Basis Profile)
- MyBatis3.1.1 Insert 回到主键 long类型 MYSQL 数据库
- mysql:假若一个表中,有两个属性name和id,删除同名的保留id小的,问这样写有误吗
- java mysql where限制有关问题
- 救助。Mysql 的条件删除语句如何写,就是删除部门的时候,如果部门下有用户,就不能删除
- mysql 触发器 根据更新的这一列的数据来更新本行的另一列数据解决办法
- 数据库Sqlserver,Sybase,orcale,mysql 用jDBC 做分页操作的查询效率有什麽区别解决办法
- HashMap无法显示。show()解决思路
- sql+mysql+chart+DataTable实现折线图分享!解决方案
- sql+mysql+chart+DataTable兑现折线图分享
- 当触发 onclick="show(this.id)"> 后,滚动条如何搞都会跑到最下面,怎么保持滚动条
- mysql diopdownlist连接数据库,该怎么解决
- MySQL 自动增长列的有关问题?求高手指导,小弟我是学生
- MySQL 主键和自增列的有关问题 新手在学 求指导
- Unable to connect to any of the specified MySQL hosts为什么连不上mysql?该如何解决
- show.aspx页面怎样绑定数据,唯一标志一篇文章。解决方案
- 在SP1的VS下找不到类 Profile ,请用过的
- mysql 的存储过程变量如何在 sql 中使用