测量实际的 MySQL 查询时间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11274892/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 14:01:05  来源:igfitidea点击:

Measuring actual MySQL query time

mysqloptimization

提问by Mikhail

How can I measure the execution time of a query without measuring the time it spends waiting for a lock release etc? My only idea was to continuously measure same query and record the fastest time.

如何测量查询的执行时间而不测量它等待锁定释放等所花费的时间?我唯一的想法是不断测量相同的查询并记录最快的时间。

回答by fancyPants

Start the profiler with

启动探查器

SET profiling = 1;

Then execute your Query.

然后执行您的查询。

With

SHOW PROFILES;

you see a list of queries the profiler has statistics for. And finally you choose which query to examine with

您会看到分析器具有统计信息的查询列表。最后您选择要检查的查询

SHOW PROFILE FOR QUERY 1;

or whatever number your query has.

或您查询的任何数字。

What you get is a list where exactly how much time was spent during the query.

您得到的是一个列表,其中列出了查询期间花费了多少时间。

More info in the manual.

手册中的更多信息

回答by Rick James

The accepted Answer is becoming invalid...

接受的答案变得无效...

SHOW PROFILE[S]are deprecated as of MySQL 5.6.7and will be removed in a future MySQL release. Use the Performance Schema instead; see http://dev.mysql.com/doc/refman/5.6/en/performance-schema-query-profiling.html

SHOW PROFILE[S]弃用的MySQL 5.6.7的,并会在将来的MySQL版本中删除。改用性能模式;见http://dev.mysql.com/doc/refman/5.6/en/performance-schema-query-profiling.html