- Cassandra 教程
- Cassandra - 首頁
- Cassandra - 簡介
- Cassandra - 架構
- Cassandra - 資料模型
- Cassandra - 安裝
- Cassandra - 參考 API
- Cassandra - Cqlsh
- Cassandra - Shell 命令
- Cassandra Keyspace 操作
- Cassandra - 建立 Keyspace
- Cassandra - 修改 Keyspace
- Cassandra - 刪除 Keyspace
- Cassandra 表操作
- Cassandra - 建立表
- Cassandra - 修改表
- Cassandra - 刪除表
- Cassandra - 清空表
- Cassandra - 建立索引
- Cassandra - 刪除索引
- Cassandra - 批處理
- Cassandra CURD 操作
- Cassandra - 建立資料
- Cassandra - 更新資料
- Cassandra - 讀取資料
- Cassandra - 刪除資料
- Cassandra CQL 型別
- Cassandra - CQL 資料型別
- Cassandra - CQL 集合
- CQL 使用者定義資料型別
- Cassandra 有用資源
- Cassandra - 快速指南
- Cassandra - 有用資源
- Cassandra - 討論
Cassandra - Shell 命令
除了 CQL 命令,Cassandra 還提供了已記錄的 shell 命令。下面是 Cassandra 已記錄的 shell 命令。
幫助
HELP 命令顯示所有 cqlsh 命令的摘要和簡要描述。以下是 help 命令的用法。
cqlsh> help Documented shell commands: =========================== CAPTURE COPY DESCRIBE EXPAND PAGING SOURCE CONSISTENCY DESC EXIT HELP SHOW TRACING. CQL help topics: ================ ALTER CREATE_TABLE_OPTIONS SELECT ALTER_ADD CREATE_TABLE_TYPES SELECT_COLUMNFAMILY ALTER_ALTER CREATE_USER SELECT_EXPR ALTER_DROP DELETE SELECT_LIMIT ALTER_RENAME DELETE_COLUMNS SELECT_TABLE
捕獲
此命令捕獲命令的輸出並將其新增到檔案中。例如,請檢視以下捕獲輸出到名為 Outputfile 檔案的程式碼。
cqlsh> CAPTURE '/home/hadoop/CassandraProgs/Outputfile'
當我們在終端中輸入任何命令時,輸出將被給定的檔案捕獲。以下是使用的命令和輸出檔案的快照。
cqlsh:tutorialspoint> select * from emp;
您可以使用以下命令關閉捕獲。
cqlsh:tutorialspoint> capture off;
一致性
此命令顯示當前一致性級別,或設定新的一個一致性級別。
cqlsh:tutorialspoint> CONSISTENCY Current consistency level is 1.
複製
此命令將資料從 Cassandra 複製到檔案或從檔案複製到 Cassandra。以下是一個將名為 emp 的表複製到 myfile 檔案的示例。
cqlsh:tutorialspoint> COPY emp (emp_id, emp_city, emp_name, emp_phone,emp_sal) TO ‘myfile’; 4 rows exported in 0.034 seconds.
如果您開啟並驗證給定的檔案,您可以找到如下所示的複製資料。
描述
此命令描述 Cassandra 的當前叢集及其物件。此命令的變體在下面解釋。
描述叢集 - 此命令提供有關叢集的資訊。
cqlsh:tutorialspoint> describe cluster;
Cluster: Test Cluster
Partitioner: Murmur3Partitioner
Range ownership:
-658380912249644557 [127.0.0.1]
-2833890865268921414 [127.0.0.1]
-6792159006375935836 [127.0.0.1]
描述 Keyspaces - 此命令列出叢集中的所有 Keyspaces。以下是此命令的用法。
cqlsh:tutorialspoint> describe keyspaces; system_traces system tp tutorialspoint
描述表 - 此命令列出 Keyspace 中的所有表。以下是此命令的用法。
cqlsh:tutorialspoint> describe tables; emp
描述表 - 此命令提供表的描述。以下是此命令的用法。
cqlsh:tutorialspoint> describe table emp;
CREATE TABLE tutorialspoint.emp (
emp_id int PRIMARY KEY,
emp_city text,
emp_name text,
emp_phone varint,
emp_sal varint
) WITH bloom_filter_fp_chance = 0.01
AND caching = '{"keys":"ALL", "rows_per_partition":"NONE"}'
AND comment = ''
AND compaction = {'min_threshold': '4', 'class':
'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy',
'max_threshold': '32'}
AND compression = {'sstable_compression':
'org.apache.cassandra.io.compress.LZ4Compressor'}
AND dclocal_read_repair_chance = 0.1
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND read_repair_chance = 0.0
AND speculative_retry = '99.0PERCENTILE';
CREATE INDEX emp_emp_sal_idx ON tutorialspoint.emp (emp_sal);
描述型別
此命令用於描述使用者定義的資料型別。以下是此命令的用法。
cqlsh:tutorialspoint> describe type card_details; CREATE TYPE tutorialspoint.card_details ( num int, pin int, name text, cvv int, phone set<int>, mail text );
描述型別
此命令列出所有使用者定義的資料型別。以下是此命令的用法。假設有兩個使用者定義的資料型別:card 和 card_details。
cqlsh:tutorialspoint> DESCRIBE TYPES; card_details card
擴充套件
此命令用於擴充套件輸出。在使用此命令之前,您必須開啟 expand 命令。以下是此命令的用法。
cqlsh:tutorialspoint> expand on;
cqlsh:tutorialspoint> select * from emp;
@ Row 1
-----------+------------
emp_id | 1
emp_city | Hyderabad
emp_name | ram
emp_phone | 9848022338
emp_sal | 50000
@ Row 2
-----------+------------
emp_id | 2
emp_city | Delhi
emp_name | robin
emp_phone | 9848022339
emp_sal | 50000
@ Row 3
-----------+------------
emp_id | 4
emp_city | Pune
emp_name | rajeev
emp_phone | 9848022331
emp_sal | 30000
@ Row 4
-----------+------------
emp_id | 3
emp_city | Chennai
emp_name | rahman
emp_phone | 9848022330
emp_sal | 50000
(4 rows)
注意 - 您可以使用以下命令關閉 expand 選項。
cqlsh:tutorialspoint> expand off; Disabled Expanded output.
退出
此命令用於終止 cql shell。
顯示
此命令顯示當前 cqlsh 會話的詳細資訊,例如 Cassandra 版本、主機或資料型別假設。以下是此命令的用法。
cqlsh:tutorialspoint> show host; Connected to Test Cluster at 127.0.0.1:9042. cqlsh:tutorialspoint> show version; [cqlsh 5.0.1 | Cassandra 2.1.2 | CQL spec 3.2.0 | Native protocol v3]
源
使用此命令,您可以執行檔案中的命令。假設我們的輸入檔案如下所示 -
然後,您可以執行包含命令的檔案,如下所示。
cqlsh:tutorialspoint> source '/home/hadoop/CassandraProgs/inputfile';
emp_id | emp_city | emp_name | emp_phone | emp_sal
--------+-----------+----------+------------+---------
1 | Hyderabad | ram | 9848022338 | 50000
2 | Delhi | robin | 9848022339 | 50000
3 | Pune | rajeev | 9848022331 | 30000
4 | Chennai | rahman | 9848022330 | 50000
(4 rows)