问题
I am newbie in Cassandra and trying to implement one toy application using Cassandra. I had created one keyspace and few column families in my Cassandra DB but I forgot the name of my cluster.
I am trying to find if there is any query which can list down all the available keyspaces.
Anybody knows such a query or command?
回答1:
If you want to do this outside of the cqlsh
tool you can query the schema_keyspaces
table in the system
keyspace. There's also a table called schema_columnfamilies
which contains information about all tables.
The DESCRIBE
and SHOW
commands only work in cqlsh
and cassandra-cli
.
回答2:
[cqlsh 4.1.0 | Cassandra 2.0.4 | CQL spec 3.1.1 | Thrift protocol 19.39.0]
Currently, the command to use is:
DESCRIBE keyspaces;
回答3:
Its very simple. Just give the below command for listing all keyspaces.
Cqlsh> Describe keyspaces;
If you want to check the keyspace in the system schema using the SQL query
below is the command.
SELECT * FROM system_schema.keyspaces;
Hope this will answer your question...
You can go through the explanation on understanding and creating the keyspaces from below resources.
Documentation:
https://docs.datastax.com/en/cql/3.1/cql/cql_reference/create_keyspace_r.html https://www.i2tutorials.com/cassandra-tutorial/cassandra-create-keyspace/
回答4:
Found it...show keyspaces
command lists down all the keyspaces. I think earlier when I tried this command, I forgot to give last 's' in 'keyspaces'
回答5:
The DESCRIBE
command is your friend. You can describe one keyspace, list keyspaces, one table or list all tables in keyspace, the cluster and much more.
You can get the full idea by typing
HELP DESCRIBE
in cqlsh.
Connected to mscluster at 127.0.0.1:9042. [cqlsh 5.0.1 | Cassandra 3.8 | CQL spec 3.4.2 | Native protocol v4] Use HELP for help.
cqlsh> HELP DESCRIBE
DESCRIBE [cqlsh only] (DESC may be used as a shorthand.) Outputs information about the connected Cassandra cluster, or about the data objects stored in the cluster. Use in one of the following ways:...<omitted for brevity>
- DESCRIBE
<your key space name>
- describes the command used to create keyspace
cqlsh> DESCRIBE testkeyspace;
CREATE KEYSPACE testkeyspace WITH replication = {'class':'SimpleStrategy', 'replication_factor': '3'} AND durable_writes = true;
- DESCRIBE keyspaces - lists all keyspaces
cqlsh> DESCRIBE KEYSPACES
system_schema system testkeyspace system_auth
system_distributed system_traces
- DESCRIBE TABLES - List all tables in current keyspace
cqlsh:system> DESCRIBE TABLES;
available_ranges peers paxos
range_xfers batches compaction_history batchlog
local "IndexInfo" sstable_activity
size_estimates hints views_builds_in_progress peer_events
built_views
- DESCRIBE
your table name
or DESCRIBE TABLEyour table name
- Gives the table details
cqlsh:system> DESCRIBE TABLE batchlog
CREATE TABLE system.batchlog ( id uuid PRIMARY KEY, data blob, version int, written_at timestamp ) WITH bloom_filter_fp_chance = 0.01 AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'} AND comment = 'DEPRECATED batchlog entries' ....omitted for brevity
回答6:
DESC KEYSPACES will do the job.
Also, If you want to describe schema of a particular keyspace you can use
DESC
回答7:
Once logged in to cqlsh or cassandra-cli. run below commands
- On cqlsh
desc keyspaces;
or
describe keyspaces;
or
select * from system_schema.keyspaces;
- On cassandra-cli
show keyspaces;
回答8:
- login to cqlsh
- desc keyspaces;
- select * from system_schema.keyspaces ;
回答9:
desc keyspaces will do it for you.
回答10:
DESCRIBE keyspaces to list all keysapces DESCRIBE keyspace https://docs.datastax.com/en/dse/5.1/cql/cql/cql_reference/cqlsh_commands/cqlshDescribeKeyspace.html
回答11:
I suggest a combination of grep
and awk
:
root@DC1-Node1:/home# nodetool tablestats | grep "Keyspace :" | awk -F ":" '{print $2}'
system_traces
system
system_distributed
system_schema
device_tool
system_tool
回答12:
Apart from above method, if you have opscenter installed,
- Go to data tab > there you will see all keyspcaces created by you and some system keyspaces.
- You can see all tables under individual keyspaces and also replicator factor for keyspace.
for more details check below link. https://docs.datastax.com/en/opscenter/6.1/opsc/online_help/opscDataModelingManagingKeyspace_t.html
回答13:
describes and desc command will give list of keyspaces in the cluster.Please find below output for more details.
cqlsh> describe keyspaces
reaper_db system_auth system_distributed
system_schema system system_traces
OR
cqlsh> desc keyspaces
reaper_db system_auth system_distributed
system_schema system system_traces
来源:https://stackoverflow.com/questions/18712967/how-to-list-all-the-available-keyspaces-in-cassandra