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