thelma
thelma

Reputation: 193

How, using Python, can I find how long a MySQL query took?

I'm connecting to MySQL with the MySQLdb module. I don't want to use Python's time functions: I want to know how long the query ran within MySQL, i.e. the number I see after I've run a query within MySQL directly.

I do see a thread where this is addressed as something one could eventually dig down to, but I was hoping that since MySQL reports that number, the Python connection would have picked it up somewhere.

Upvotes: 2

Views: 301

Answers (1)

BAE
BAE

Reputation: 8936

May this help?

SET profiling = 1;
Run your query;
SHOW PROFILES;

See here:http://dev.mysql.com/doc/refman/5.7/en/show-profile.html

Because of the above commands will be removed in the future version,  Performance Schema can be used http://dev.mysql.com/doc/refman/5.7/en/performance-schema.html and http://dev.mysql.com/doc/refman/5.7/en/performance-schema-query-profiling.html

On the above links, there are more details on Query Profiling Using Performance Schema. 

Upvotes: 1

Related Questions