zoukankan      html  css  js  c++  java
  • cassandra CQL 常用操作

    1. CQL客户端链接

       bin/cqlsh ip username password 

    2. 

    (1)建立keyspace语句,keyspace类似于 mysql 中的数据库,一个数据库中可以有很多表;

    CREATE KEYSPACE mykeyspace WITH REPLICATION = { 'class' : 'SimpleStrategy','replication_factor' : 2 } ,replication_factor 表示 数据被复制几份

    (2)建表语句:

    CREATE TABLE task ( row_split text, column_split text, username text, parent_user text, priority int, url text, status int, is_dir boolean, channel_code text, is_multilayer boolean, action_type int, create_time bigint, finish_time bigint, id text, subtask_result text, reason text, retry_time int, PRIMARY KEY (row_split, column_split) ) ;  primary key 的第一个元素是rowkey,第二个元素的是cluster key;
     
    (3)建索引语句:
    create index task_status on task(status);  cassandra的索引不支持范围查找,类似于 位图索引 或者 哈希索引,支持 = 操作,不支持< 或 > 之类的范围查找;
     
    (4)查询语句,
    select * from task where status=2;
    注意,cassandra where 子句里面的,除了rowkey以外,其他字段如果要使用 = 操作,必须建立二级索引,而且cassandra里面的二级索引 不支持范围查询,类似于位图索引,不同于 BTREE索引;
     
    (5)删除语句,
    单独删除某个column 或者 某行;
    delete column1,column2 from table where rowkey = 'xxxx' 
    or 
    delete column1,column2 from table where rowkey in ('x','xx','xxx'...)
    其中where子句是不能省略的。
     
    (6)删除表中的所有数据
    如果要想实现 类似 mysql中 delete from table的效果,可以使用truncate;
     
    truncate table
  • 相关阅读:
    How Default Heap Of Process Grows
    希腊字母表
    Ubuntu第一次亲密接触
    Ubuntu中的挂载点(mount point)
    要一专多能
    First touch with JIT debugging
    小学一下环境变量
    安装VMware Tools
    [转]ReiserFS与ext3的比较
    [bbk4485]第二章Flashback Database 05
  • 原文地址:https://www.cnblogs.com/yuhan-TB/p/4745429.html
Copyright © 2011-2022 走看看