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
  • 相关阅读:
    矿场和矿池有什么区别?
    石墨烯技术到底是什么?
    区块链技术如何解决网络犯罪?
    区块链+AI将给区块链带来怎样的改变?
    区块链技术具体包含哪些方面?
    2018年加密货币税率为0%的国家盘点
    what??|诞生才一年的BCH竟面临硬分叉的抉择
    币圈黑客在偷到币后是如何销脏的?
    选择器
    纯js+html+css实现模拟时钟
  • 原文地址:https://www.cnblogs.com/yuhan-TB/p/4745429.html
Copyright © 2011-2022 走看看