Mysql – Measure query execution time in bash

bashMySQLquerytime

I need to measure a query total execution time from inside a bash script.

Somebody told me to submit something like:

mysql --user="someuser" --password="pw" -D "dbname" -e 'your-sql-command;' 

Is it right?

But how can I get the timing stats I need?

Best Answer

time

as in

tom.oconnor@charcoal-black:/tmp$ time ls -lah
total 20K
drwxrwxrwt 26 root        root    4.0K 2012-04-11 15:28 .
drwxr-xr-x 23 root        root    4.0K 2012-04-03 15:01 ..


real    0m0.003s
user    0m0.010s
sys     0m0.000s

Cool, huh?

From the time manpage

TIME(1)                                  TIME(1)

NAME
       time - run programs and summarize system resource usage