1. 创建键空间
CREATE KEYSPACE <identifier> WITH <properties>
cqlsh> CREATE KEYSPACE test01 WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '3'} AND durable_writes = true;
cqlsh> CREATE KEYSPACE test02 WITH replication = {'class': 'NetworkTopologyStrategy', 'DC1': 1, 'DC2': 3} AND durable_writes = 'true';
简单的策略:为集群指定简单的复制因子。
网络拓扑策略:可以单独为每个数据中心设置复制因子。
旧网络拓扑策略:可以单独为每个数据中心设置复制因子。
切换keyspace
cqlsh> USE test01 ;
cqlsh:test01> DESCRIBE TABLES;
<empty>
2. 修改键空间
ALTER KEYSPACE <identifier> WITH <properties>
cqlsh:test01> ALTER KEYSPACE test01 WITH replication = {'class': 'NetworkTopologyStrategy', 'DC1': 1, 'DC2': 3} AND durable_writes = 'true';
cqlsh:system> 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'}
test02 | True | {'DC1': '1', 'DC2': '3', 'class': 'org.apache.cassandra.locator.NetworkTopologyStrategy'}
system_traces | True | {'class': 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '2'}
test01 | True | {'DC1': '1', 'DC2': '3', 'class': 'org.apache.cassandra.locator.NetworkTopologyStrategy'}
(7 rows)
3. 删除键空间
DROP KEYSPACE <identifier>
cqlsh:system> DROP KEYSPACE test02 ;
cqlsh:system> DESC KEYSPACES ;
system_schema system_auth system system_distributed system_traces test01
本文详细介绍如何在Cassandra中创建、修改和删除键空间,包括使用不同的复制策略,如简单策略和网络拓扑策略,并展示了如何查看键空间的详细信息。


被折叠的 条评论
为什么被折叠?



