在从文件重定向sql输入时为mysql命令行获取相同的输出(批处理模式)

kb5ga3dv  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(328)

这看起来很简单,但我不知道如何解决它。
下面是一个简单的sql脚本:

select c1 from t1 where c1='notPresent';

我使用交互式shell执行它,如:

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

          Empty set (0.00 sec)

现在我执行它为:

mysql -u somebody -psomePassword myDatabase < myFile.sql

输出为:

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

我知道如何通过在my.cnf中保存userid和密码来抑制此警告,但我也想获得“空集”输出。
sql更新也是如此。当脚本来自文件时,它不会以更新的行数显示状态。
这是一个更大的应用程序的一部分。我已把问题缩小到上述情况。

toiithl6

toiithl61#

您可以使用三重详细模式以批处理模式获取完整输出:

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

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

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

Bye

我在查看帮助时发现了这个选项:

mysql --help

...

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

相关问题