0

When I run a SQL statement interactively in a MySQL 5.7 client it tells me how long the query ran:

mysql> select now();
--------------
select now()
--------------
+---------------------+
| now() |
+---------------------+
| 2018年03月09日 14:27:42 |
+---------------------+
1 row in set (0.07 sec)

In this case it ran for 0.07 seconds.

But when I run the same SQL statement through a script the output does not include the time the statement took.

>mysql -f -v --table -u myuser -pmypassword -h myhost mydb < test.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
--------------
select now()
--------------
+---------------------+
| now() |
+---------------------+
| 2018年03月09日 14:31:00 |
+---------------------+

How can I run a SQL statement from a script and still get back the length of time that it ran using the MySQL 5.7 client?

Thanks! Bobby

asked Mar 9, 2018 at 20:37
2
  • 1
    Does adding more verbosity -v -v -v -v help? Commented Mar 9, 2018 at 22:33
  • 1
    I thought I had looked at the -v flag but didn't read the manual carefully enough to see that you could have it multiple times. I'm new to mysql. Thanks for saving me time. Commented Mar 12, 2018 at 15:57

1 Answer 1

2

You can use -vvv with mysql command.

mysql -f -vvv --table -u myuser -pmypassword -h myhost mydb < test.sql
> mysql -vvv < mysql.sql 
--------------
select now()
--------------
+---------------------+
| now() |
+---------------------+
| 2018年03月10日 04:08:33 |
+---------------------+
1 row in set (0.00 sec)
Bye

Hope it will fulfill your requirement :)

answered Mar 9, 2018 at 22:48
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.