bash 从命令行运行 cassandra 查询
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42829949/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Run cassandra queries from command line
提问by 4EACH
I want to execute cql queries from bash command.
我想从 bash 命令执行 cql 查询。
[cqlsh 3.1.8 | Cassandra 1.2.19 | CQL spec 3.0.5 | Thrift protocol 19.36.2]
[cqlsh 3.1.8 | 卡桑德拉 1.2.19 | CQL 规范 3.0.5 | 节俭协议 19.36.2]
[root@hostname ~]# /opt/apache-cassandra-1.2.19/bin/cqlsh -k "some_keyspace" -e "SELECT column FROM Users where key=value"
I got:
我有:
cqlsh: error: no such option: -e
cqlsh:错误:没有这样的选项:-e
Options:
选项:
--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
Any suggestions ?
有什么建议 ?
采纳答案by 4EACH
It's bit dirty and unstable, but here is the answer:
它有点脏而且不稳定,但这是答案:
/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
回答by Aaron
First of all, you should seriously consider upgrading. You are missing out on a lot of new features and bug fixes.
首先,你应该认真考虑升级。您错过了许多新功能和错误修复。
Secondly, with cqlsh in Cassandra 1.2 you can use the -f
flag to specify a file containing cql statements:
其次,使用 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)
回答by juniormint88
You can use -f to execute from a file or SOURCE once you start CQLSH. I don't think -e is a valid option with that version.
启动 CQLSH 后,您可以使用 -f 从文件或 SOURCE 执行。我不认为 -e 是该版本的有效选项。