Cassandra basic operations using cqlsh

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

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


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

查看所有标签

猜你喜欢:

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

计算机程序设计艺术 第2卷 半数值算法(第3版)(英文影印版)

计算机程序设计艺术 第2卷 半数值算法(第3版)(英文影印版)

(美)Donald E.Knuth / 清华大学出版社 / 2002-09-01 / 83.0

计算机程序设计艺术:英文版(第2卷 半数值算法),ISBN:9787302058151,作者:(美)Donald E. Knuth著一起来看看 《计算机程序设计艺术 第2卷 半数值算法(第3版)(英文影印版)》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

MD5 加密
MD5 加密

MD5 加密工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器