cqlsh操作cassandra

使用python客户端工具


C:\apache-cassandra-2.1.2-bin\apache-cassandra-2.1.2\bin>cqlsh.bat
Connection error: ('Unable to connect to any servers', {'127.0.0.1': ConnectionE
xception('Timed out connecting to 127.0.0.1',)})
C:\apache-cassandra-2.1.2-bin\apache-cassandra-2.1.2\bin>cqlsh.bat
Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 2.1.2 | CQL spec 3.2.0 | Native protocol v3]
Use HELP for help.
WARNING: pyreadline dependency missing.  Install to enable tab completion.
创建空间,可以理解为创建数据库
cqlsh> CREATE KEYSPACE mykeyspace WITH REPLICATION = { 'class' : 'SimpleStrategy
', 'replication_factor' : 1 };
使用空间,可以理解为使用数据库
cqlsh> USE mykeyspace;
创建表:
cqlsh:mykeyspace> CREATE TABLE users (user_id int PRIMARY KEY,fname text,lname t
ext);
插入数据:
cqlsh:mykeyspace> INSERT INTO users (user_id,  fname, lname) VALUES (1745, 'john
', 'smith');
cqlsh:mykeyspace> INSERT INTO users (user_id,  fname, lname) VALUES (1744, 'john
', 'doe');
cqlsh:mykeyspace> INSERT INTO users (user_id,  fname, lname) VALUES (1746, 'john
', 'smith');
查询表:
cqlsh:mykeyspace> SELECT * FROM users;
 
 user_id | fname | lname
---------+-------+-------
    1745 |  john | smith
    1744 |  john |   doe
    1746 |  john | smith
 
(3 rows)
创建索引
cqlsh:mykeyspace> CREATE INDEX ON users (lname);
cqlsh:mykeyspace> SELECT * FROM users WHERE lname = 'smith';
 
 user_id | fname | lname
---------+-------+-------
    1745 |  john | smith
    1746 |  john | smith
 
(2 rows)
cqlsh:mykeyspace>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值