【问题标题】:cqlsh equivalent to mysql -ecqlsh 相当于 mysql -e
【发布时间】:2014-08-01 09:38:51
【问题描述】:

我正在尝试创建一个小型 shell 脚本,以便我通过 cqlsh 直接从命令行运行命令。

在 MySQL 中我可以这样做:

mysql -u root  -e "show databases;"

是否有与-e 等效的 cqlsh,或者是将我要运行的任何命令放在文件中并使用 -f 的最接近的等效项?

谢谢

【问题讨论】:

    标签: shell cassandra cqlsh


    【解决方案1】:

    对于一次性命令,cqlsh 4.1.1 还具有 -e 选项:

    $cqlsh -e 'desc keyspaces' -u myusername -p mypassword localhost
    
    branch     stackoverflow  products  system_auth  
    customers  system         branches  system_traces
    

    如果你有一些复杂的东西,比如多行命令序列,那么cqlsh 上的-f 选项应该是你想要做的。为了演示,我将创建一个名为 descTables.cql 的简单 cql 脚本文件,如下所示:

    $ cat descTables.cql
    use stackoverflow;
    desc tables;
    

    现在,我将使用 cqlsh -f 调用该 cql 脚本:

    $cqlsh -f descTables.cql -u myusername -p mypassword localhost
    
    datasimple  items
    

    仅供参考-看起来最新版本的 2.0 具有 cqlsh 4.1.1,它具有 -e 标志。在我的一个实例上,我有 4.1.0,但 -e 选项不可用。

    【讨论】:

    【解决方案2】:

    下面列出了更多选项:

    1. "-C", "--color", action='store_true', dest='color', help='总是使用 颜色输出'
    2. "--no-color", action='store_false', dest='color', help='从不使用 颜色输出'
    3. "-u", "--username", help="以用户身份验证。"
    4. "-p", "--password", help="使用密码进行身份验证。"
    5. '-k', '--keyspace', help='验证给定的keyspace。'
    6. "-f", "--file", help="从文件执行命令,然后退出"
    7. "-t", "--transport-factory", help="使用提供的Thrift传输 工厂函数。”
    8. '--debug', action='store_true', help='显示附加调试 信息'
      1. '--cqlversion', default=DEFAULT_CQLVER, help='指定一个特定的 CQL 版本(默认值:%default)。'' 示例:“3.0.3”、“3.1.0”'

    【讨论】:

      猜你喜欢
      • 2017-10-16
      • 2019-10-23
      • 2016-01-01
      • 2013-11-28
      • 1970-01-01
      • 1970-01-01
      • 2011-06-26
      • 2013-03-20
      • 2012-02-21
      相关资源
      最近更新 更多