2

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?

Fabio B.
  • 299
  • 2
  • 5
  • 17

1 Answers1

3

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
Tom O'Connor
  • 27,440
  • 10
  • 72
  • 148
  • 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
  • 1
    in bash you'd get the help for the time modifier with `help time` – stew Apr 11 '12 at 14:53