[关闭]
@contribute 2016-09-07T02:28:02.000000Z 字数 1514 阅读 3309

cassandra-cql命令行记录

cassandra



cqlsh登陆

  1. //进入cql客户端,powershell中直接用cqlsh登陆即可,cmd和命令行下需要使用cqlsh.bat进入
  2. PS D:\apache-cassandra-2.1.7\bin> .\cqlsh
  3. Connected to Test Cluster at 127.0.0.1:9042.
  4. [cqlsh 5.0.1 | Cassandra 2.1.7 | CQL spec 3.2.0 | Native protocol v3]
  5. Use HELP for help.
  6. WARNING: pyreadline dependency missing. Install to enable tab completion.
  7. cqlsh>

显示keyspace

  1. //显示keyspace
  2. cqlsh> describe keyspaces;
  3. mykeyspace simplex system_traces system

创建keyspace

  1. //创建keyspace
  2. cqlsh> CREATE KEYSPACE IF NOT EXISTS myCas WITH REPLICATION = {'class': 'SimpleStrategy','replication_factor':1};
  3. cqlsh> describe keyspaces;
  4. mycas mykeyspace simplex system_traces system

选择keyspace

  1. //选择keyspace
  2. cqlsh> use mycas;
  3. cqlsh:mycas>

向表中添加数据

  1. //向表中添加数据
  2. cqlsh> use mycas;
  3. cqlsh:mycas> INSERT INTO users (id,user_name) VALUES (1,'zhangsan');
  4. cqlsh:mycas> select * from users;
  5. id | user_name
  6. ----+-----------
  7. 1 | zhangsan

从表中查询数据

  1. //从表中查询数据
  2. cqlsh:mycas> select * from users where id=1;
  3. id | user_name
  4. ----+-----------
  5. 1 | zhangsan
  6. (1 rows)
  7. cqlsh:mycas> select * from users where user_name='zhangsan';
  8. InvalidRequest: code=2200 [Invalid query] message="No secondary indexes on the restricted columns support the provided o
  9. perators: "

删除表中数据

  1. //删除表中数据
  2. SyntaxException: <ErrorMessage code=2000 [Syntax error in CQL query] message="line 1:17 mismatched input ';' expecting K
  3. _WHERE">
  4. cqlsh:mycas> delete from users where id=1;
  5. cqlsh:mycas> select * from users;
  6. id | user_name
  7. ----+-----------
  8. (0 rows)

创建索引

  1. //创建索引
  2. cqlsh:mycas> create index on users(user_name);
  3. cqlsh:mycas> select * from users where user_name='zhangsan';
  4. id | user_name
  5. ----+-----------
  6. 1 | zhangsan
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注