@contribute
2016-09-07T02:28:02.000000Z
字数 1514
阅读 3486
cassandra
//进入cql客户端,powershell中直接用cqlsh登陆即可,cmd和命令行下需要使用cqlsh.bat进入PS D:\apache-cassandra-2.1.7\bin> .\cqlshConnected to Test Cluster at 127.0.0.1:9042.[cqlsh 5.0.1 | Cassandra 2.1.7 | CQL spec 3.2.0 | Native protocol v3]Use HELP for help.WARNING: pyreadline dependency missing. Install to enable tab completion.cqlsh>
//显示keyspacecqlsh> describe keyspaces;mykeyspace simplex system_traces system
//创建keyspacecqlsh> CREATE KEYSPACE IF NOT EXISTS myCas WITH REPLICATION = {'class': 'SimpleStrategy','replication_factor':1};cqlsh> describe keyspaces;mycas mykeyspace simplex system_traces system
//选择keyspacecqlsh> use mycas;cqlsh:mycas>
//向表中添加数据cqlsh> use mycas;cqlsh:mycas> INSERT INTO users (id,user_name) VALUES (1,'zhangsan');cqlsh:mycas> select * from users;id | user_name----+-----------1 | zhangsan
//从表中查询数据cqlsh:mycas> select * from users where id=1;id | user_name----+-----------1 | zhangsan(1 rows)cqlsh:mycas> select * from users where user_name='zhangsan';InvalidRequest: code=2200 [Invalid query] message="No secondary indexes on the restricted columns support the provided operators: "
//删除表中数据SyntaxException: <ErrorMessage code=2000 [Syntax error in CQL query] message="line 1:17 mismatched input ';' expecting K_WHERE">cqlsh:mycas> delete from users where id=1;cqlsh:mycas> select * from users;id | user_name----+-----------(0 rows)
//创建索引cqlsh:mycas> create index on users(user_name);cqlsh:mycas> select * from users where user_name='zhangsan';id | user_name----+-----------1 | zhangsan