Cassandra basic operations using cqlsh

栏目: 数据库 · 发布时间: 8年前

内容简介:Cassandra basic operations using cqlsh

本文是公司使用一段时间Cassandra后的总结,主要是一些基础操作,比较难理解的是Cassandra的 where 操作。我并没有详细列出,而是给了Datastax的一篇文章链接。

Basic

  • Cassandra 2.2.5 docker run -d --net host --name cca cassandra:2.2.5
  • pip install cqlsh

login

cqlsh cca_ip  
cqlsh -u cassandra -p cassandra cca_ip

keyspace

  • show keyspaces
cassandra@cqlsh:raw> describe keyspaces;  
raw  system_distributed  system_auth  system  system_traces
  • use keyspace
use raw;
  • create keyspace
CREATE KEYSPACE IF NOT EXISTS raw WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': 1 }

指定了负责备份数据的类 SimpleStrategy ,和备份因子 replication_factor (可以根据集群中node的数量调整)。

  • drop keyspace
drop keyspace keyspace_name;  
drop keyspace raw;
  • alter(change) keyspace
ALTER KEYSPACE “KeySpace Name”  
WITH replication = {'class': ‘Strategy name’, 'replication_factor' : ‘No.Of  replicas’};

reference: alter keyspace

table

  • show tables
cassandra@cqlsh:raw> describe tables;  
process_info_v1  cpu_usage_v1  container_info_v1  server_info_v1  mem_usage_v1
  • create table
CREATE TABLE tablename(  
   column1 name datatype PRIMARYKEY,
   column2 name data type,
   column3 name data type.
   )

reference: create table

  • alter table
  • add column
ALTER TABLE table name  
ADD  new column datatype;
drop table table_name;

CQL (like SQL)

select

select * from table

insert

insert into table (column1,...,column4) values (v1,...,v4)

update

UPDATE <tablename>  
SET <column name> = <new value>  
<column name> = <value>....  
WHERE <condition>

reference

detele

DELETE FROM <identifier> WHERE <condition>;  
cqlsh:tutorialspoint> DELETE FROM emp WHERE emp_id=3;

reference

where clause

Cassandra是分布式列式NoSQL数据库,和 SQL 数据库在许多方面都有区别。CQL中的主键 Primary key 和SQL中的 Primary key 有本质区别,这导致在 where 子句上会有区别。

A deep look at the CQL WHERE clause


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Joy of X

The Joy of X

Niall Mansfield / UIT Cambridge Ltd. / 2010-7-1 / USD 14.95

Aimed at those new to the system seeking an overall understanding first, and written in a clear, uncomplicated style, this reprint of the much-cited 1993 classic describes the standard windowing syste......一起来看看 《The Joy of X》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

MD5 加密
MD5 加密

MD5 加密工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具