Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 2 down vote accepted


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)

       time - run programs and summarize system resource usage
share|improve this answer
note however, that the time manpage documents /usr/bin/time and running time as you did is using the shell command modifier (assuming something like bash or zsh) (try which time or type time) – stew Apr 11 '12 at 14:53
in bash you'd get the help for the time modifier with help time – stew Apr 11 '12 at 14:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.