cassandra数据库使用(二)–cql进行数据基本操作
文章目录
一、介绍
这里介绍cassandra使用cql(cassandra query language)进行表和数据操作。
二、cassandrar的库表定义
cassandra是面向列的分布式的nosql数据库。定义和mysql类似。
2.1 keyspace
相当于数据库schema
2.2 table
和mysql中的table定义一样
三、cassandra的数据类型
cassandra数据类型除了基本类型外,还添加了集合类型,如list、set、map。
下面列出常用的类型(第一列为cassandra中的类似,第二列为相应描述,第三列为java中的类型),
################## 常用字段类型 ##########################
int 32位整数 int
bigint 64整数 long
float 32位浮点数 flaot
counter 计数器,支持原子性增减,不能直接赋值 long
double 64位浮点数 double
boolean 布尔 boolean
decimal 高精度小数 BigDecimal
list 列表 List
set 集合 Set
map 键值对 map
text utf8编码的字符串 String
varchar 与text一样
timestamp 日期 Date
############################################################
四、创建cassandra的cql会话连接
切到cassandra安装根目录下
命令:
bin/cqlsh host port
参数:
-e 要执行的语句
-u 用户名
-p 密码
-k 指定keyspace
如:
#!/usr/bin/env bash
cqlsh_bin="cassandra/bin/cqlsh"
host="192.168.0.1"
port=9042
cqlsh_conn="${cqlsh_bin} ${host} ${port}"