Sunny
Sunny

Reputation: 10075

Getting same output for mysql command line when SQL input is redirected from file (Batch mode)

This appears to be simple, but I cannot figure out how to fix it.

Here is a simple sql script:

   select c1 from t1 where c1='notPresent';

I execute it using interactive shell as in:

   mysql -u somebody -psomePassword myDatabase
   ...
   mysql> select c1 from t1 where c1='notPresent';

          Empty set (0.00 sec)

Now I execute it as:

    mysql -u somebody -psomePassword myDatabase < myFile.sql

The output is:

        mysql: [Warning] Using a password on the command line interface can be insecure.

I know how to suppress this warning by saving the userId and password in my.cnf but I want to get the "Empty set" output too.

The same with SQL Updates. When script is from a file, it does not display status as in number of row updated.

This is part of a bigger application. I have narrowed the problem to the above situation.

Upvotes: 1

Views: 345

Answers (1)

Bill Karwin
Bill Karwin

Reputation: 562328

You can use triple-verbose mode to get full output in batch mode:

echo "show tables" | mysql -v -v -v test 

--------------
show tables
--------------

+--------------------+
| Tables_in_test     |
+--------------------+
| ........           |
+--------------------+
2 rows in set (0.00 sec)

Bye

I spotted this option when I looked at the help:

mysql --help

...

-v, --verbose       Write more. (-v -v -v gives the table output format).

Upvotes: 1

Related Questions