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