Cassandra basic operations using cqlsh

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

内容简介: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


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

查看所有标签

猜你喜欢:

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

Head First HTML and CSS

Head First HTML and CSS

Elisabeth Robson、Eric Freeman / O'Reilly Media / 2012-9-8 / USD 39.99

Tired of reading HTML books that only make sense after you're an expert? Then it's about time you picked up Head First HTML and really learned HTML. You want to learn HTML so you can finally create th......一起来看看 《Head First HTML and CSS》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

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

在线 XML 格式化压缩工具