课程表

Cassandra 基础

Cassandra 键空间操作

Cassandra 表操作

Cassandra CURD操作

Cassandra CQL数据类型

工具箱
速查手册

Cassandra Shell命令

当前位置:免费教程 » 数据库/运维 » Cassandra

除了CQL命令,Cassandra还提供了记录的shell命令。下面给出了Cassandra记录的shell命令。

Help

HELP命令显示所有cqlsh命令的摘要和简要描述。下面给出了help命令的用法。

  1. cqlsh> help
  2.  
  3. Documented shell commands:
  4. ===========================
  5. CAPTURE COPY DESCRIBE EXPAND PAGING SOURCE
  6. CONSISTENCY DESC EXIT HELP SHOW TRACING.
  7.  
  8. CQL help topics:
  9. ================
  10. ALTER CREATE_TABLE_OPTIONS SELECT
  11. ALTER_ADD CREATE_TABLE_TYPES SELECT_COLUMNFAMILY
  12. ALTER_ALTER CREATE_USER SELECT_EXPR
  13. ALTER_DROP DELETE SELECT_LIMIT
  14. ALTER_RENAME DELETE_COLUMNS SELECT_TABLE

Capture

此命令捕获命令的输出并将其添加到文件。例如,看看下面的代码,它将输出捕获到名为Outputfile的文件。

  1. cqlsh> CAPTURE '/home/hadoop/CassandraProgs/Outputfile'

当我们在终端中键入任何命令时,输出将被给定的文件捕获。下面给出的是使用的命令和输出文件的快照。

  1. cqlsh:tutorialspoint> select * from emp;
文件

您可以使用以下命令关闭捕获。

  1. cqlsh:tutorialspoint> capture off;

Consistency

此命令显示当前的一致性级别,或设置新的一致性级别。

  1. cqlsh:tutorialspoint> CONSISTENCY
  2. Current consistency level is 1.

Copy

此命令将数据从Cassandra复制到文件并从中复制。下面给出一个将名为emp的表复制到文件myfile的示例。

  1. cqlsh:tutorialspoint> COPY emp (emp_id, emp_city, emp_name, emp_phone,emp_sal) TO myfile’;
  2. 4 rows exported in 0.034 seconds.

如果您打开并验证给定的文件,您可以找到复制的数据,如下所示。

文件2

Describe

此命令描述Cassandra及其对象的当前集群。此命令的变体说明如下。

Describe cluster -此命令提供有关集群的信息。

  1. cqlsh:tutorialspoint> describe cluster;
  2.  
  3. Cluster: Test Cluster
  4. Partitioner: Murmur3Partitioner
  5.  
  6. Range ownership:
  7. -658380912249644557 [127.0.0.1]
  8. -2833890865268921414 [127.0.0.1]
  9. -6792159006375935836 [127.0.0.1]

Describe Keyspaces -此命令列出集群中的所有键空间。下面给出了这个命令的用法。

  1. cqlsh:tutorialspoint> describe keyspaces;
  2.  
  3. system_traces system tp tutorialspoint

Describe tables -此命令列出了键空间中的所有表。下面给出了这个命令的用法。

  1. cqlsh:tutorialspoint> describe tables;
  2. emp

Describe tables -此命令提供表的描述。下面给出了这个命令的用法。

  1. cqlsh:tutorialspoint> describe table emp;
  2.  
  3. CREATE TABLE tutorialspoint.emp (
  4. emp_id int PRIMARY KEY,
  5. emp_city text,
  6. emp_name text,
  7. emp_phone varint,
  8. emp_sal varint
  9. ) WITH bloom_filter_fp_chance = 0.01
  10. AND caching = '{"keys":"ALL", "rows_per_partition":"NONE"}'
  11. AND comment = ''
  12. AND compaction = {'min_threshold': '4', 'class':
  13. 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy',
  14. 'max_threshold': '32'}
  15. AND compression = {'sstable_compression':
  16. 'org.apache.cassandra.io.compress.LZ4Compressor'}
  17. AND dclocal_read_repair_chance = 0.1
  18. AND default_time_to_live = 0
  19. AND gc_grace_seconds = 864000
  20. AND max_index_interval = 2048
  21. AND memtable_flush_period_in_ms = 0
  22. AND min_index_interval = 128
  23. AND read_repair_chance = 0.0
  24. AND speculative_retry = '99.0PERCENTILE';
  25. CREATE INDEX emp_emp_sal_idx ON tutorialspoint.emp (emp_sal);

Describe tables

此命令用于描述用户定义的数据类型。下面给出了这个命令的用法。

  1. cqlsh:tutorialspoint> describe type card_details;
  2.  
  3. CREATE TYPE tutorialspoint.card_details (
  4. num int,
  5. pin int,
  6. name text,
  7. cvv int,
  8. phone set<int>,
  9. mail text
  10. );

Describe Types

此命令列出所有用户定义的数据类型。下面给出了这个命令的用法。假设有两种用户定义的数据类型:card和card_details。

  1. cqlsh:tutorialspoint> DESCRIBE TYPES;
  2.  
  3. card_details card

Expand

此命令用于扩展输出。在使用此命令之前,您必须打开expand命令。下面给出了这个命令的用法。

  1. cqlsh:tutorialspoint> expand on;
  2. cqlsh:tutorialspoint> select * from emp;
  3.  
  4. @ Row 1
  5. -----------+------------
  6. emp_id | 1
  7. emp_city | Hyderabad
  8. emp_name | ram
  9. emp_phone | 9848022338
  10. emp_sal | 50000
  11. @ Row 2
  12. -----------+------------
  13. emp_id | 2
  14. emp_city | Delhi
  15. emp_name | robin
  16. emp_phone | 9848022339
  17. emp_sal | 50000
  18. @ Row 3
  19. -----------+------------
  20. emp_id | 4
  21. emp_city | Pune
  22. emp_name | rajeev
  23. emp_phone | 9848022331
  24. emp_sal | 30000
  25. @ Row 4
  26. -----------+------------
  27. emp_id | 3
  28. emp_city | Chennai
  29. emp_name | rahman
  30. emp_phone | 9848022330
  31. emp_sal | 50000
  32. (4 rows)

注意:您可以使用以下命令关闭展开选项。

  1. cqlsh:tutorialspoint> expand off;
  2. Disabled Expanded output.

Exit

此命令用于终止cql shell。

Show

此命令显示当前cqlsh会话的详细信息,如Cassandra版本,主机或数据类型假设。下面给出了这个命令的用法。

  1. cqlsh:tutorialspoint> show host;
  2. Connected to Test Cluster at 127.0.0.1:9042.
  3.  
  4. cqlsh:tutorialspoint> show version;
  5. [cqlsh 5.0.1 | Cassandra 2.1.2 | CQL spec 3.2.0 | Native protocol v3]

Source

使用此命令,可以在文件中执行命令。假设我们的输入文件如下:

源1

然后可以执行包含命令的文件,如下所示。

  1. cqlsh:tutorialspoint> source '/home/hadoop/CassandraProgs/inputfile';
  2.  
  3. emp_id | emp_city | emp_name | emp_phone | emp_sal
  4. --------+-----------+----------+------------+---------
  5. 1 | Hyderabad | ram | 9848022338 | 50000
  6. 2 | Delhi | robin | 9848022339 | 50000
  7. 3 | Pune | rajeev | 9848022331 | 30000
  8. 4 | Chennai | rahman | 9848022330 | 50000
  9. (4 rows)
转载本站内容时,请务必注明来自W3xue,违者必究。
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号