Home > Database > Mysql Tutorial > 浅谈MySQL的Profiler工具

浅谈MySQL的Profiler工具

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 17:22:41
Original
1424 people have browsed it

在大数据量的应用中,常常需要对数据库配置和SQL语句进行优化,以保证应用在负载大数据量时的并发性。MySQL内置有分析器Profiler

在大数据量的应用中,常常需要对数据库配置和SQL语句进行优化,以保证应用在负载大数据量时的并发性。MySQL内置有分析器Profiler,通过Profiler,开发者能够方便快速的了解MySQL大概的性能。

使用Profiler非常简单,只需设置系统变量“profiling = on”或“profiling = 1”,默认情况下,Profiler是关闭的,可以通过命令“SELECT @@profiling;”或“SHOW variables LIKE ‘%profiling%’;”查看Profiler状态。如图所示:

浅谈MySQL的Profiler工具

浅谈MySQL的Profiler工具

执行命令“SET profiling = on;”或“SET profiling = 1;”后,就能使用Profiler了。

例如:假设现在有一个数据库demo,demo里有一个数据表tab_demo,其结构如图所示:

浅谈MySQL的Profiler工具

通过命令“SELECT * FROM tab_demo;”查询表中所有记录,返回结果如图所示:

浅谈MySQL的Profiler工具

下面使用Profiler查看以上数据库操作的具体情况。运行命令“SHOW profiles;”,返回每次操作花费时间,如图所示:

浅谈MySQL的Profiler工具

为了更清楚的查看每次操作数据库具体做了哪些事情,例如:想要查看第4次Query操作的具体流程,可以通过命令“SHOW profile FOR query 4;”,返回结果如图所示:

浅谈MySQL的Profiler工具

从图中可以清晰的看到执行一条SQL语句的具体流程,包括:初始化,打开表,锁定表等。这样就能大概了解在哪一步花费时间较多,从而可以针对性的对数据库或SQL语句进行优化。

总的来说,在进行数据库性能分析时,,Profiler可以作为一种简单快速的分析工具,先通过它大概的获取一些信息,再配合其它专门的性能分析工具,可以取得很好的效果。

linux

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template