2012-01-18
這篇的說明是以Cassandra 1.0.6版為基準,早期版本可能沒有cqlsh功能。此外,在系統中已先自行建立testks keyspace,並在裡面建了employee columnfamily。
cqlsh功能簡述如下
在Cassandra 1.x版後,除了cassandra-cli之外,在
/cassandra_install_folder/bin
裡多了個cqlsh的指令。該指令跟cassandra-cli一樣是個client端工具,可用來連線至server端進行資料維護與查詢。cqlsh有個很大的好處,那就是「支援CQL語法操作」,要查資料時比用cassandra-cli來的輕鬆;但是...也有個很大的問題,cqlsh是在python之上執行,如果OS本身沒裝python,cqlsh就變成看的到吃不到的功能。至於要怎麼安裝?官網完全沒跟你講,也就是說...如果你完全不懂python,你根本連裝都不會裝,更不用提怎麼用了...囧rz
安裝cqlsh可參考下列步驟
===========================================================================
Ubuntu linux平台的安裝方式如下
python -V
sudo sh setuptools-0.6c11-py2.7.egg
easy_install -h
sudo easy_install cql
cqlsh 127.0.0.1 9160
cqlsh -u admin -p adminpwd 127.0.0.1 9160
cloudtu@cloudtu-VirtualBox:~/cassandra-1.0.6-1/bin$ ./cqlsh 127.0.0.1 9160===========================================================================
Connected to Test Cluster at 127.0.0.1:9160.
[cqlsh 2.0.0 | Cassandra 1.0.6 | CQL spec 2.0.0 | Thrift protocol 19.19.0]
Use HELP for help.
cqlsh> use testks;
cqlsh:testks> select * from employee;
KEY | age | dept | name |
3 | 3 | rd | tester3 |
6 | 6 | mis | tester6 |
5 | 5 | rd | tester5 |
19 | 19 | rd | tester19 |
10 | 10 | mis | tester10 |
8 | 8 | mis | tester8 |
2 | 2 | mis | tester2 |
16 | 16 | mis | tester16 |
13 | 13 | rd | tester13 |
1 | 1 | rd | tester1 |
12 | 12 | mis | tester12 |
9 | 9 | rd | tester9 |
14 | 14 | mis | tester14 |
4 | 4 | mis | tester4 |
15 | 15 | rd | tester15 |
11 | 11 | rd | tester11 |
20 | 20 | mis | tester20 |
18 | 18 | mis | tester18 |
7 | 7 | rd | tester7 |
17 | 17 | rd | tester17 |
cqlsh:testks> quit;
cloudtu@cloudtu-VirtualBox:~/cassandra-1.0.6-1/bin$
C:\Python\Python27
。python -V
python ez_setup.py
C:\Python\Python27\Scripts
,執行下面這行指令可看到easy_install指令的相關說明。easy_install -h
easy_install cql
python cqlsh 127.0.0.1 9160
python cqlsh -u admin -p adminpwd 127.0.0.1 9160
Z:\apache-cassandra-1.0.6\bin>python cqlsh 127.0.0.1 9160===========================================================================
Connected to Test Cluster at 127.0.0.1:9160.
[cqlsh 2.0.0 | Cassandra 1.0.6 | CQL spec 2.0.0 | Thrift protocol 19.19.0]
Use HELP for help.
cqlsh> use testks;
cqlsh:testks> select * from employee;
KEY | age | dept | name |
3 | 3 | rd | tester3 |
6 | 6 | mis | tester6 |
5 | 5 | rd | tester5 |
19 | 19 | rd | tester19 |
10 | 10 | mis | tester10 |
8 | 8 | mis | tester8 |
2 | 2 | mis | tester2 |
16 | 16 | mis | tester16 |
13 | 13 | rd | tester13 |
1 | 1 | rd | tester1 |
12 | 12 | mis | tester12 |
9 | 9 | rd | tester9 |
14 | 14 | mis | tester14 |
4 | 4 | mis | tester4 |
15 | 15 | rd | tester15 |
11 | 11 | rd | tester11 |
20 | 20 | mis | tester20 |
18 | 18 | mis | tester18 |
7 | 7 | rd | tester7 |
17 | 17 | rd | tester17 |
cqlsh:testks> quit;
Z:\apache-cassandra-1.0.6\bin>