Cassandra - 鍵空間keyspace 操作

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

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章