【问题标题】:Run cassandra queries from command line从命令行运行 cassandra 查询
【发布时间】:2017-08-07 09:12:28
【问题描述】:

我想从 bash 命令执行 cql 查询。

[cqlsh 3.1.8 |卡桑德拉 1.2.19 | CQL 规范 3.0.5 | Thrift 协议 19.36.2]

[root@hostname ~]# /opt/apache-cassandra-1.2.19/bin/cqlsh -k "some_keyspace" -e "SELECT column FROM Users where key=value"

我明白了:

cqlsh:错误:没有这样的选项:-e

选项:

  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -C, --color           Always use color output
  --no-color            Never use color output
  -u USERNAME, --username=USERNAME
                        Authenticate as user.
  -p PASSWORD, --password=PASSWORD
                        Authenticate using password.
  -k KEYSPACE, --keyspace=KEYSPACE
                        Authenticate to the given keyspace.
  -f FILE, --file=FILE  Execute commands from FILE, then exit
  -t TRANSPORT_FACTORY, --transport-factory=TRANSPORT_FACTORY
                        Use the provided Thrift transport factory function.
  --debug               Show additional debugging information
  --cqlversion=CQLVERSION
                        Specify a particular CQL version (default: 3.0.5).
                        Examples: "2", "3.0.0-beta1"
  -2, --cql2            Shortcut notation for --cqlversion=2
  -3, --cql3            Shortcut notation for --cqlversion=3

有什么建议吗?

【问题讨论】:

  • 怎么样:cqlsh -e "SELECT column FROM some_keyspace.Users where key=value;"
  • 运行 cqlsh -h 以获取支持的选项

标签: bash cassandra cql cqlsh cassandra-cli


【解决方案1】:

首先,您应该认真考虑升级。您错过了许多新功能和错误修复。

其次,在 Cassandra 1.2 中使用 cqlsh,您可以使用 -f 标志来指定包含 cql 语句的文件:

$ echo "use system_auth; SELECT role,is_superuser FROM roles WHERE role='cassandra';" > userQuery.cql
$ bin/cqlsh -u aploetz -p reindeerFlotilla -f userQuery.cql 

 role      | is_superuser
-----------+--------------
 cassandra |         True


(1 rows)

【讨论】:

  • 好的,我怎样才能只输出列值?没有列名和下划线
  • 哪个版本开始支持 -e 标志?
  • @4EACH -e 标志是在 Cassandra 2.0 中引入的。
【解决方案2】:

一旦启动 CQLSH,就可以使用 -f 从文件或 SOURCE 执行。我认为 -e 不是该版本的有效选项。

【讨论】:

    【解决方案3】:

    它有点脏且不稳定,但这里是答案:

    /opt/apache-cassandra-1.2.19/bin/cqlsh -k "keyspace" -f  /path/to/file.cql  > /path/to/output.txt
    tail -2 /path/to/output.txt | head -1 > /path/to/output-value.txt
    

    【讨论】:

      猜你喜欢
      • 2013-11-09
      • 2022-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-18
      • 2016-05-09
      • 1970-01-01
      • 2017-01-14
      相关资源
      最近更新 更多