在cqlsh 2中是否有像“show keyspaces”这样清晰的等价命令?

47

我应该使用哪个cqlsh命令来快速查看集群中的键空间? cqlsh没有提供show keyspaces,而describe cluster不够简洁。


我正在使用以下规格:

cqlsh 2.2.0,Cassandra 1.1.10,CQL规范2.0.0,Thrift协议19.33.0

4个回答

107

非常简单。只需在您的cqlsh shell中输入此命令,即可享受。

 select * from system.schema_keyspaces;

在 C*3.x 中,我们可以简单地使用

 describe keyspaces

发现在此页面底部列出的指令:http://www.datastax.com/docs/1.1/dml/using_cql - Crowie
5
system.schema_keyspaces表似乎已从c* 3.x系列中移除。 - BSB

47

只需尝试这个:

describe keyspaces

然而,您可能需要以下规格(而不是由您自己提到的Crowie)的大致内容:

[cqlsh 4.1.1 | Cassandra 2.0.6 | CQL spec 3.1.1 | Thrift protocol 19.39.0]


13
cqlsh> select * from system_schema.keyspaces;

 keyspace_name      | durable_writes | replication
--------------------+----------------+-------------------------------------------------------------------------------------
        system_auth |           True | {'class': 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '1'}
      system_schema |           True |                             {'class': 'org.apache.cassandra.locator.LocalStrategy'}
 system_distributed |           True | {'class': 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '3'}
             system |           True |                             {'class': 'org.apache.cassandra.locator.LocalStrategy'}
      system_traces |           True | {'class': 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '2'}

3
注意:这适用于 Cassandra 3.0。您可以使用以下查询验证您的版本:SELECT release_version from system.local;参考:从system.schema_keyspaces查询生成code=2200 - benSooraj

4
C* 3.x系列的正确方法是:
List<KeyspaceMetadata> keyspaces = Cluster.getMetadata().getKeyspaces()

然后在KeyspaceMetadata实例上使用getName()函数。

1
嘿Bsb。我认为这个答案只涉及到当你想在Java中获取这些信息时。是这样吗?我的问题旨在专注于cqlsh控制台查询。如果我看起来有点不对劲,那就抱歉...显然,我几年前问过这个问题,现在也没有使用C*。我问这个问题是为了让我可以通过编辑改进您的答案,或者可能点赞并改进其他答案。 - Crowie

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接