Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 2 down vote accepted

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
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
1  
in bash you'd get the help for the time modifier with help time –  stew Apr 11 '12 at 14:53
add comment

Your Answer

 
discard

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.