Cassandra cqlsh使用

启动cqlsh

  • bin/cqlsh $host $port -u $username -p $password
    • 通过 IP地址 和端口 Cassandra 用户名、密码 进入cqlsh
  • demo:cqlsh -u hujunde -p Hujunde0402
  • demo2:cqlsh 192.168.227.22 -u hujunde -p Hujunde0402 进入 cqlsh;

在cqlsh 里面查看环境变量

  • cqlsh> describe cluster;
    Cluster: Test Cluster
    Partitioner: Murmur3Partitioner
    • describe cluster 显示集群的名字以及采用的partitioner。
  • cqlsh> describe keyspaces;
    • 查看集群里面可用的keyspaces
      system_schema system system_distributed system_traces system_auth test_keyspace test
  • cqlsh> show version
    • [cqlsh 5.0.1 | Cassandra 3.11.6 | CQL spec 3.4.4 | Native protocol v4]

cqlsh 创建keyspace

  • Cassandra 作为NoSQL数据,一个keyspace 可以包含一个或多个 tables 或 column families
  • 创建 keyspaces;使用use,命令切换到这个keyspace,use test_keyspace;
  • CREATE KEYSPACE WITH
  • demo1:CREATE KEYSPACE test_keyspace WITH replication = {‘class’: ‘SimpleStrategy’, ‘replication_factor’: ‘1’} AND durable_writes = true;
  • demo2:CREATE KEYSPACE test WITH replication = {‘class’: ‘NetworkTopologyStrategy’, ‘datacenter1’: ‘2’} AND durable_writes = false;

cqlsh 创建table

  • CREATE (TABLE | COLUMNFAMILY)
    (’’ , ‘’)
    (WITH AND )
  • demo1: CREATE TABLE test_user (first_name text , last_name text, PRIMARY KEY (first_name)) ;
  • demo2: CREATE TABLE test.ais2019 (
    utc text,
    dim text,
    id text,
    long text
    primary key(id,utc)
    )with clustering order by (utc asc)
  • 在上面的示例中,我们所创建的Primary Key就是一个由两个列id和utc组成的Compound Primary Key。其中该Compound Primary Key的第一个组成被称为是Partition Key,而后面的各组成则被称为是Clustering Key。Partition Key用来决定Cassandra会使用集群中的哪个结点来记录该数据,每个Partition Key对应着一个特定的Partition。而Clustering Key则用来在Partition内部排序。如果一个Primary Key只包含一个域,那么其将只拥有Partition Key而没有Clustering Key。

cqlsh读写table数据

  • INSERT INTO test_user (first_name, last_name) VALUES (‘test’, ‘Hadoop’);
  • SELECT * FROM test_user;
  • 大批量数据(csv file)导入 COPY table_name [( column_list )]
    FROM ‘file_name’[, ‘file2_name’, …] | STDIN
    [WITH option = ‘value’ [AND …]]
  • demo1:copy myks.mytable from ‘/path/to/test.file’ with delimiter=’|’ and header=true;
  • 数据导出(csv file):copy myks.mytable to ‘/Users/qiaojialin/Desktop/test.csv’ with delimiter=’|’ and header=true;

通过 cqlsh删除列或行

  • 删除last_name 列数据 :DELETE last_name FROM test_user WHERE first_name=‘test’;
  • 删除一整行数据:ELETE FROM test_user WHERE first_name=‘test’;

通过 cqlsh清空表

  • 截断表,表中的所有行都将 永久删除 ;TRUNCATE test_user;

通过 cqlsh小批量Cassandra数据导入导出

导出数据
Copies data from a table to a CSV file.
COPY

[(, …)] TO WITH [AND …]
导入数据
Copies data from a CSV file to table.
COPY
[(, …)] FROM WITH [AND …]
https://blog.youkuaiyun.com/qiaojialin/article/details/80306563?utm_source=blogxgwz1 导入导出数据未总结

来源:
https://help.aliyun.com/document_detail/127012.html?spm=a2c4g.11186623.6.555.49101429vU9GsN
https://www.w3cschool.cn/cassandra/cassandra_create_keyspace.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值