Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
740 views
in Technique[技术] by (71.8m points)

sql - how to get load time in milliseconds or microseconds in mysql

I' ve searched and searched, but I wasn't able to find an easy way to get this:

Query OK, 50000 rows affected (0.35 sec) 

in milliseconds or microseconds.

How can I achieve it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I came with the same problem, I did my queries from a linux console using time

$ time mysql --user="user" -D "DataBase" -e "SELECT SQL_NO_CACHE COUNT(1) FROM table"

 ------------
 count(1)
 ------------
 750
 ------------

 real 0m0.269s
 user 0m0.014s
 sys  0m0.015s

or

$ time -f"%e" mysql --user="user" -D "DataBase" -e "SELECT SQL_NO_CACHE COUNT(1) FROM table"

------------
 count(1)
------------
 750
------------
 0.24

It gives different values from "mysql" but at least is something you can work with, for example this script:

#!/bin
temp = 1
while [ $temp -le 1000]
do
    /usr/bin/time -f"%e" -o"/home/admin/benchmark.txt" -a mysql --user="user" -D "DataBase" -e "SELECT SQL_NO_CACHE COUNT(1) FROM table"  > /dev/null 2> /dev/null
    let temp=$temp+1
done

Execute the query 1000 times, -f shows only the real time, -o the output file, -a appends to the output, > /dev/null 2> /dev/null ignores the query output so it doesn't print in console each time.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...