Cassandra CQL用法

Cassandra CQL用法Cassandra

  • Cassandra
  • Tools
  • cqlsh: the CQL shell
  • Edit

cqlsh: the CQL shell

cqlsh is a command-line interface for interacting with Cassandra using CQL (the Cassandra Query Language). It is shipped with every Cassandra package, and can be found in the bin/ directory alongside the cassandra executable. cqlsh is implemented with the Python native protocol driver, and connects to the single specified node.

Compatibility

cqlsh is compatible with Python 2.7.

In general, a given version of cqlsh is only guaranteed to work with the version of Cassandra that it was released with. In some cases, cqlsh may work with older or newer versions of Cassandra, but this is not officially supported.

Optional Dependencies

cqlsh ships with all essential dependencies. However, there are some optional dependencies that can be installed to improve the capabilities of cqlsh.

pytz

By default, cqlsh displays all timestamps with a UTC timezone. To support display of timestamps with another timezone, install the pytz library. See the timezone option in cqlshrc for specifying a timezone to use.

cython

The performance of cqlsh’s COPY operations can be improved by installing cython. This will compile the python modules that are central to the performance of COPY.

cqlshrc

The cqlshrc file holds configuration options for cqlsh. By default, the file is locagted the user’s home directory at ~/.cassandra/cqlsh, but a custom location can be specified with the --cqlshrc option.

Example config values and documentation can be found in the conf/cqlshrc.sample file of a tarball installation. You can also view the latest version of the cqlshrc file online.

Command Line Options

Usage:

cqlsh [options] [host [port]]

Options:

-C --color

Force color output

--no-color

Disable color output

--browser

Specify the browser to use for displaying cqlsh help. This can be one of the supported browser names (e.g. firefox) or a browser path followed by %s (e.g. /usr/bin/google-chrome-stable %s).

--ssl

Use SSL when connecting to Cassandra

-u --user

Username to authenticate against Cassandra with

-p --password

Password to authenticate against Cassandra with, should be used in conjunction with --user

-k --keyspace

Keyspace to authenticate to, should be used in conjunction with --user

-f --file

Execute commands from the given file, then exit

--debug

Print additional debugging information

--encoding

Specify a non-default encoding for output (defaults to UTF-8)

--cqlshrc

Specify a non-default location for the cqlshrc file

-e --execute

Execute the given statement, then exit

--connect-timeout

Specify the connection timeout in seconds (defaults to 2s)

--python /path/to/python

Specify the full path to Python interpreter to override default on systems with multiple interpreters installed

--request-timeout

Specify the request timeout in seconds (defaults to 10s)

-t --tty

Force tty mode (command prompt)

Special Commands

In addition to supporting regular CQL statements, cqlsh also supports a number of special commands that are not part of CQL. These are detailed below.

CONSISTENCY

UsageCONSISTENCY

Sets the consistency level for operations to follow. Valid arguments include:

  • ANY
  • ONE
  • TWO
  • THREE
  • QUORUM
  • ALL
  • LOCAL_QUORUM
  • LOCAL_ONE
  • SERIAL
  • LOCAL_SERIAL

SERIAL CONSISTENCY

UsageSERIAL CONSISTENCY

Sets the serial consistency level for operations to follow. Valid arguments include:

  • SERIAL
  • LOCAL_SERIAL

The serial consistency level is only used by conditional updates (INSERTUPDATE and DELETE with an IF condition). For those, the serial consistency level defines the consistency level of the serial phase (or “paxos” phase) while the normal consistency level defines the consistency for the “learn” phase, i.e. what type of reads will be guaranteed to see the update right away. For example, if a conditional write has a consistency level of QUORUM (and is successful), then a QUORUM read is guaranteed to see that write. But if the regular consistency level of that write is ANY, then only a read with a consistency level of SERIAL is guaranteed to see it (even a read with consistency ALL is not guaranteed to be enough).

SHOW VERSION

Prints the cqlsh, Cassandra, CQL, and native protocol versions in use. Example:

cqlsh> SHOW VERSION [cqlsh 5.0.1 | Cassandra 3.8 | CQL spec 3.4.2 | Native protocol v4]

SHOW HOST

Prints the IP address and port of the Cassandra node that cqlsh is connected to in addition to the cluster name. Example:

cqlsh> SHOW HOST Connected to Prod_Cluster at 192.0.0.1:9042.

SHOW SESSION

Pretty prints a specific tracing session.

UsageSHOW SESSION

Example usage:

cqlsh> SHOW SESSION 95ac6470-327e-11e6-beca-dfb660d92ad8 Tracing session: 95ac6470-327e-11e6-beca-dfb660d92ad8 activity | timestamp | source | source_elapsed | client -----------------------------------------------------------+----------------------------+-----------+----------------+----------- Execute CQL3 query | 2016-06-14 17:23:13. | 127.0.0.1 | 0 | 127.0.0.1 Parsing SELECT * FROM system.local; [SharedPool-Worker-1] | 2016-06-14 17:23:13. | 127.0.0.1 | 3843 | 127.0.0.1 ...

SOURCE

Reads the contents of a file and executes each line as a CQL statement or special cqlsh command.

UsageSOURCE

Example usage:

cqlsh> SOURCE '/home/calvinhobbs/commands.cql'

CAPTURE

Begins capturing command output and appending it to a specified file. Output will not be shown at the console while it is captured.

Usage:

CAPTURE ' 
  
    '; CAPTURE OFF; CAPTURE; 
  

That is, the path to the file to be appended to must be given inside a string literal. The path is interpreted relative to the current working directory. The tilde shorthand notation ('~/mydir') is supported for referring to $HOME.

Only query result output is captured. Errors and output from cqlsh-only commands will still be shown in the cqlsh session.

To stop capturing output and show it in the cqlsh session again, use CAPTURE OFF.

To inspect the current capture configuration, use CAPTURE with no arguments.

HELP

Gives information about cqlsh commands. To see available topics, enter HELP without any arguments. To see help on a topic, use HELP
. Also see the --browser argument for controlling what browser is used to display help.

TRACING

Enables or disables tracing for queries. When tracing is enabled, once a query completes, a trace of the events during the query will be printed.

Usage:

TRACING ON TRACING OFF

PAGING

Enables paging, disables paging, or sets the page size for read queries. When paging is enabled, only one page of data will be fetched at a time and a prompt will appear to fetch the next page. Generally, it’s a good idea to leave paging enabled in an interactive session to avoid fetching and printing large amounts of data at once.

Usage:

PAGING ON PAGING OFF PAGING 
  

EXPAND

Enables or disables vertical printing of rows. Enabling EXPAND is useful when many columns are fetched, or the contents of a single column are large.

Usage:

EXPAND ON EXPAND OFF

LOGIN

Authenticate as a specified Cassandra user for the current session.

Usage:

LOGIN 
  
    [ 
   
     ] 
    
  

EXIT

Ends the current session and terminates the cqlsh process.

Usage:

EXIT QUIT

CLEAR

Clears the console.

Usage:

CLEAR CLS

DESCRIBE

Prints a description (typically a series of DDL statements) of a schema element or the cluster. This is useful for dumping all or portions of the schema.

Usage:

DESCRIBE CLUSTER DESCRIBE SCHEMA DESCRIBE KEYSPACES DESCRIBE KEYSPACE 
  
    DESCRIBE TABLES DESCRIBE TABLE 
   
     DESCRIBE MATERIALIZED VIEW 
    
      DESCRIBE TYPES DESCRIBE TYPE 
     
       DESCRIBE FUNCTIONS DESCRIBE FUNCTION 
      
        DESCRIBE AGGREGATES DESCRIBE AGGREGATE 
        
       
      
     
    
   
     DESCRIBE INDEX 
   

In any of the commands, DESC may be used in place of DESCRIBE.

The DESCRIBE CLUSTER command prints the cluster name and partitioner:

cqlsh> DESCRIBE CLUSTER Cluster: Test Cluster Partitioner: Murmur3Partitioner

The DESCRIBE SCHEMA command prints the DDL statements needed to recreate the entire schema. This is especially useful for dumping the schema in order to clone a cluster or restore from a backup.

COPY TO

Copies data from a table to a CSV file.

Usage:

COPY 
  
    , ...)] TO 
   
     WITH 
    
      [AND 
     
       ...] 
      
     
    
   
  
    [( 
  

If no columns are specified, all columns from the table will be copied to the CSV file. A subset of columns to copy may be specified by adding a comma-separated list of column names surrounded by parenthesis after the table name.

The 
 should be a string literal (with single quotes) representing a path to the destination file. This can also the special value STDOUT (without single quotes) to print the CSV to stdout.

See shared-copy-options for options that apply to both COPY TO and COPY FROM.

Options for COPY TO

MAXREQUESTS

The maximum number token ranges to fetch simultaneously. Defaults to 6.

PAGESIZE

The number of rows to fetch in a single page. Defaults to 1000.

PAGETIMEOUT

By default the page timeout is 10 seconds per 1000 entries in the page size or 10 seconds if pagesize is smaller.

BEGINTOKENENDTOKEN

Token range to export. Defaults to exporting the full ring.

MAXOUTPUTSIZE

The maximum size of the output file measured in number of lines; beyond this maximum the output file will be split into segments. -1 means unlimited, and is the default.

ENCODING

The encoding used for characters. Defaults to utf8.

COPY FROM

Copies data from a CSV file to table.

Usage:

COPY 
  
    , ...)] FROM 
   
     WITH 
    
      [AND 
     
       ...] 
      
     
    
   
  
    [( 
  

If no columns are specified, all columns from the CSV file will be copied to the table. A subset of columns to copy may be specified by adding a comma-separated list of column names surrounded by parenthesis after the table name.

The 
 should be a string literal (with single quotes) representing a path to the source file. This can also the special value STDIN (without single quotes) to read the CSV data from stdin.

See shared-copy-options for options that apply to both COPY TO and COPY FROM.

Options for COPY TO

INGESTRATE

The maximum number of rows to process per second. Defaults to .

MAXROWS

The maximum number of rows to import. -1 means unlimited, and is the default.

SKIPROWS

A number of initial rows to skip. Defaults to 0.

SKIPCOLS

A comma-separated list of column names to ignore. By default, no columns are skipped.

MAXPARSEERRORS

The maximum global number of parsing errors to ignore. -1 means unlimited, and is the default.

MAXINSERTERRORS

The maximum global number of insert errors to ignore. -1 means unlimited. The default is 1000.

ERRFILE =

A file to store all rows that could not be imported, by default this is import_

_

.err

 where 

 is your keyspace and 

 is your table name.

MAXBATCHSIZE

The max number of rows inserted in a single batch. Defaults to 20.

MINBATCHSIZE

The min number of rows inserted in a single batch. Defaults to 2.

CHUNKSIZE

The number of rows that are passed to child worker processes from the main process at a time. Defaults to 1000.

Shared COPY Options

Options that are common to both COPY TO and COPY FROM.

NULLVAL

The string placeholder for null values. Defaults to null.

HEADER

For COPY TO, controls whether the first line in the CSV output file will contain the column names. For COPY FROM, specifies whether the first line in the CSV input file contains column names. Defaults to false.

DECIMALSEP

The character that is used as the decimal point separator. Defaults to ..

THOUSANDSSEP

The character that is used to separate thousands. Defaults to the empty string.

BOOLSTYlE

The string literal format for boolean values. Defaults to True,False.

NUMPROCESSES

The number of child worker processes to create for COPY tasks. Defaults to a max of 4 for COPY FROM and 16 for COPY TO. However, at most (num_cores – 1) processes will be created.

MAXATTEMPTS

The maximum number of failed attempts to fetch a range of data (when using COPY TO) or insert a chunk of data (when using COPY FROM) before giving up. Defaults to 5.

REPORTFREQUENCY

How often status updates are refreshed, in seconds. Defaults to 0.25.

RATEFILE

An optional file to output rate statistics to. By default, statistics are not output to a file.

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/201515.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月20日 上午9:13
下一篇 2026年3月20日 上午9:13


相关推荐

  • 嵌入式Linux–menuconfig详解

    嵌入式Linux–menuconfig详解menuconfig工作原理menuconfig是一套图像化配置工具,由ncurses库提供软件支持。ncurses库提供了一系列的函数以便使用者调用它们去生成基于文本的用户界面。menuconfig本身的软件只负责提供menuconfig工作的这一套逻辑,比如说通过上下左右调整光标,Enter选中等,并不负责提供内容。menuconfig运行之后会读取Kconfig、读取/写入….

    2022年6月11日
    31
  • 使用eclipse开发Java Web项目(最最最基础)

    使用eclipse开发Java Web项目(最最最基础)本篇首先给出 Tomcat8 0 的安装及验证过程 然后在 eclipse 中配置已安装成功的 Tomcat 服务器 最后新建一个 Javaweb 工程 并绑定已部署的 Tomcat 服务器 在工程中新建并运行 JSP 文件 通过本篇的学习 可以掌握以下内容 部署 Tomcat8 0 建立本地 Server 服务器 新建 Javaweb 开发项目 建立第一个 JSP 文件 运行 JSP 文件

    2026年3月17日
    1
  • 解决eclipse乱码问题[通俗易懂]

    解决eclipse乱码问题[通俗易懂]本文章主要解决eclipse工程区乱码问题。

    2022年5月26日
    39
  • PeakVue 振动分析技术「建议收藏」

    PeakVue 振动分析技术「建议收藏」首先声明,对于振动分析,本人是菜鸟。所以本文中可能有错误,或者不够专业和严谨。最简单的振动检测指标是所谓通频值(Overallvibrationvalue)。它是采集信号的均方根:实例:产生一个正弦波,并计算rms。该值越大,反映振动越大。importnumpyasnpfromscipyimportsignalimportmatplotlib.pyplot…

    2022年10月16日
    4
  • 网络编程socket原理_socket的基本概念和原理

    网络编程socket原理_socket的基本概念和原理一、客户机/服务器模式在TCP/IP网络中两个进程间的相互作用的主机模式是客户机/服务器模式(Client/Servermodel)。该模式的建立基于以下两点:1、非对等作用;2、通信完全是异步的。客户机/服务器模式在操作过程中采取的是主动请示方式:首先服务器方要先启动,并根据请示提供相应服务:(过程如下)1、打开一通信通道并告知本地主机,它愿意在某一个公认地址上接收客户请求。2、等待客户请求到

    2022年10月10日
    2
  • PTA浙大版《C语言程序设计(第3版)》题目集(参考代码)

    PTA浙大版《C语言程序设计(第3版)》题目集(参考代码)本题目集是博主初学 C 语言时写的 由于本题目集和另一套题目集 浙大版 C 语言程序设计实验与习题指导 第 3 版 题目集的很多题目相似 所以本题目集很多题的超链接直接指向了另一套题目集的题目 编程题 题目号题目名练习 2 1Programming 练习 2 3 输出倒三角图案练习 2 4 温度转换练习 2 6 计算物体自由下落的距离练习 2 8 计算摄氏温度练习 2 9 整数四则运算练习 2 10 计算分段函数 1 练习 2 11 计算分

    2026年3月17日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号