cqlsh 기본 사용



1. bin/cqlsh 

    - Cassandra를 위한 상호 command line interface이다.

    - 사용자가 CQL(Cassandra Query Language) 문장을 수행하여 Cassandra를 이용할 수 있다.


2. cqlsh 실행하기

    - $CASSANDRA_HOME/bin/cqlsh 를 실행한다.

    - 아래와 같은 메세지가 출력되고 prompt가 보이면 정상적으로 수행한 것이다.

[usr@svc /usr/local/cassandra/bin]$ cqlsh

Connected to Test Cluster at 127.0.0.1:9042.

[cqlsh 5.0.1 | Cassandra 3.3 | CQL spec 3.4.0 | Native protocol v4]

Use HELP for help.

cqlsh> 


3. keyspace 생성 및 사용

cqlsh> CREATE KEYSPACE mykeyspace
          WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };

cqlsh> USE mykeyspace

cqlsh:mykeyspace>


4. 테이블 생성

cqlsh:mykeyspace>CREATE TABLE users (
                           user_id int PRIMARY KEY,
                           fname text,
                           lname text
                         );


5. 데이터 삽입

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');


6. 데이터 확인

cqlsh:mykeyspace> SELECT * FROM users;

 user_id | fname | lname
---------+-------+-------
    1745 |  john | smith
    1744 |  john |   doe
    1746 |  john | smith


7. 인덱스 생성 및 조건 검색

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


8. 기타 참고 사항

   - Cassandra 3.3 버전에서 cqlsh를 실행하기 위해서는 Python 2.7 버전이 반드시 설치되어 있어야 한다.

   - 참고 : Cassandra 설치 1 - 사전 작업 (JDK, Python)



참고 URL : http://wiki.apache.org/cassandra/GettingStarted

'Database' 카테고리의 다른 글

RDBMS 성능 최적화 전략  (0) 2020.04.09
테이블 조인 종류(Table Join Type)  (0) 2020.03.29
SQL tuning 작업은 이제 불필요하다?  (0) 2020.03.16
Cassandra 설치 2  (0) 2016.02.11
Cassandra 설치 1 - 사전 작업 (JDK, Python)  (0) 2016.02.11

+ Recent posts