【问题标题】:Getting same output for mysql command line when SQL input is redirected from file (Batch mode)从文件重定向 SQL 输入时,mysql 命令行获得相同的输出(批处理模式)
【发布时间】:2018-09-06 16:10:06
【问题描述】:

这看起来很简单,但我不知道如何解决它。

这是一个简单的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 中保存用户 ID 和密码来抑制此警告,但我也想获得“空集”输出。

SQL 更新也是如此。当脚本来自文件时,它不会显示更新行数的状态。

这是一个更大的应用程序的一部分。我已将问题范围缩小到上述情况。

【问题讨论】:

    标签: mysql


    【解决方案1】:

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

    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).
    

    【讨论】:

    • 太棒了!谢谢!!请更新答案以匹配问题......在批处理模式下。它可以工作,但您的示例应该处于批处理模式,如果不给 -v 两次它就无法工作。
    • 你能看看这个问题。我打扰您的唯一原因是我没有收到任何建议,需要尽快完成这项工作……尽管这是周末!谢谢stackoverflow.com/questions/52244107/…
    猜你喜欢
    • 2012-05-28
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-12
    相关资源
    最近更新 更多