欢迎投稿

今日深度:

cassandra使用,

cassandra使用,


cassandra拷贝文件到csv
COPY airplanes (name, mach, year, manufacturer) TO 'export.csv';


cassandra 删除节点
1 ./nodetool status获取host id
2 ./nodetool removenode <被移除的node id>
3 ./nodetool removenode status  nodetool netstats 查看处理状态


 ./nodetool decommission 实测可用 原理:把当前主机的.db文件发送到集群的其他主机。
  执行过程中使用 ./nodetool netstats ./nodetool status跟踪执行过程



1 在cqlsh中命令要以”;”结尾,这跟MySQL等其他客户端是一样的,并且支持TAB补全及提示功能,这点比较方便,比如一个命令记不全或者一个命令会有哪些选项时,可以用TAB列出。
现在我们来建一个keyspace--表的命名空间:
#CREATE KEYSPACE market WITH replication = {'class':'SimpleStrategy', 'replication_factor': 1};
CREATE KEYSPACE demo with placement_strategy ='org.apache.cassandra.locator.SimpleStrategy' and strategy_options = [{replication_factor:1}];


连接
cassandra-cli -host 223.85.210.81 -port 9160


2 然后切换到该keyspace:
cqlsh> use mykeyspace ;
3.1 建类似关系数据表
create TABLE users(userid int PRIMARY KEY,fname text,lname text);
3.2 建KV表
CREATE COLUMNFAMILY blog_entry WITH (comparator = UTF8Type AND key_validation_class=UTF8Type AND default_validation_class = UTF8Type);
3.3 建计数表
CREATE COLUMN FAMILY page_view_counts WITH default_validation_class=CounterColumnType AND key_validation_class=UTF8Type AND comparator=UTF8Type;


CREATE TABLE T1 (
  key text,
  column1 text,
  value text,
  PRIMARY KEY ((key), column1)
) WITH COMPACT STORAGE AND
  read_repair_chance=0.1 AND
  replicate_on_write='true';


4.1 插入关系数据:
insert into users (userid, fname, lname ) VALUES ( 1,'john','smith');
insert into users (userid, fname, lname ) VALUES ( 2,'john','zhangsan');
4.2 插入KV数据
set blog_entry ['cassandra']['name']='nosql数据库';
set blog_entry ['cassandra']['time']='2016-5-27';
set blog_entry['cassandra']['state']='A';
4.3 插入counter数据
插入一行和计数列: INCR page_view_counts['www.datastax.com'][home] BY 0;
增加计数: INCR page_view_counts['www.datastax.com'][home] BY 1;


ASSUME t1 KEYS AS utf8;
ASSUME t1 COMPARATOR AS utf8;
ASSUME t1 VALIDATOR AS utf8;



5 查看数据:
select * from users;
6 待条件查询
如果要执行带where条件的查询,那么条件中指定的列必须先建索引,否则会出错
select * from users where lname = 'smith';
7 建索引
create INDEX on users(lname);




查询keyspace,可以在系统表中查询:
cqlsh> use system;
cqlsh:system> select * from schema_keyspaces;


用java代码生成的keyspace在切换时需要带引号?
cqlsh> use "BookRating";


查询表名
cqlsh> DESCRIBE TABLES




执行:
java -cp cassandraDemo.jar src.MarketLable






//java -cp cassandraDemo.jar src.BookRatingSample

www.htsjk.Com true http://www.htsjk.com/cassandra/33848.html NewsArticle cassandra使用, cassandra拷贝文件到csv COPY airplanes (name, mach, year, manufacturer) TO 'export.csv'; cassandra 删除节点 1 ./nodetool status获取host id 2 ./nodetool removenode 被移除的node id 3 ./nodetool removenode stat...
相关文章
    暂无相关文章
评论暂时关闭