使用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>