设为首页 加入收藏

TOP

cassandra-cqlsh基本操作
2019-05-11 02:31:20 】 浏览:50
Tags:cassandra-cqlsh 基本操作

Cassandra CQL操作基础

CQL是Cassandra Query Language的缩写,目前作为Cassandra默认并且主要的交互接口。CQL和SQL比较类似,主要的区别是Cassandra不支持join或子查询

在执行操作之前,首先打开命令行进入Cassandra安装目录下的bin文件夹,执行cqlsh,如果不成功可能你的cassandra没有开启,要先在bin目录下开启,即输入cassandra即可,在开启后需要在另开启一个命令行窗口执行cql

一:创建keyspace

cqlsh>CREATEKEYSPACE IFNOTEXISTSdemo1WITHREPLICATION = {'class':'SimpleStrategy','replication_factor':1};

二:查询有哪些keyspace

describe keyspaces;

可以看到已经成功创建了名为demo1的keyspace,然后开始使用。

三:选择keyspace

use demo1;(一定要切记加上;否则会一直出现...语句无法终止)

四:创建表

cqlsh:demo1> CREATE TABLE student(

... id int,

... s_name varchar,

... PRIMARY KEY(id));

五:向表中添加数据

cqlsh:demo1> INSERT INTO student (id,s_name) VALUES (1,'Naruto');

cqlsh:demo1> INSERT INTO student (id,s_name) VALUES (2,'Naruto');

六:查询数据

cqlsh:demo1> select * from student;

cqlsh:demo1> select * from student where id=2;根据主键查询

cqlsh:demo1> select * from student where s_name='Sanji';

查询没有索引的s_name无法查询.需要先创建一个索引:

cqlsh:demo1> create index on student(s_name);

七:更新数据

cqlsh:demo1> update student set s_name='Luffy' where id=1;

八:删除表数据(必须要有where条件)

cqlsh:demo1> delete from student where id=3;

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇docker入门命令教程 下一篇Java IO流学习总结

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目