mysql command line return execution time?

前端 未结 3 1665
陌清茗
陌清茗 2021-02-07 05:45

I\'m working on a Linux host with mysql command. I have a script that runs batch mysql commands (like mysql -e \"select...\") and I wish to summarize execution time

3条回答
  •  面向向阳花
    2021-02-07 06:24

    You can invoke mysql with -vv, it will pretty-print similar to when you're in interactive mode:

    $ mysql -vv -u myUser -pMyPass DBname -e 'select count(*) from mytable;'
    --------------
    select count(*) from mytable
    --------------
    
    +----------+
    | count(*) |
    +----------+
    |  1068316 |
    +----------+
    1 row in set (0.00 sec)
    
    Bye
    

    If you're piping your queries, then it's -vvv:

    $ echo 'select count(*) from mytable;' | mysql -vvv -u myUser -pMyPass DBname
    --------------
    select count(*) from mytable
    --------------
    
    +----------+
    | count(*) |
    +----------+
    |  1068316 |
    +----------+
    1 row in set (1.34 sec)
    
    Bye
    

    Time's yours to grep. :D

提交回复
热议问题