Connecting to Cassandra



There are multiple ways you can connect with cassandra database. 
  • Directly connect with node where cassandra is running
  • Run from different host using (cqlsh client ) to connect with cassandra
 Directly connect with node where cassandra is running

ssh to the any of the node where cassandra is running and run cqlsh to connect with cassandra. In my case my cassandra database is running on node1 so login to node1 using ssh and run below statement :-

Default Username : cassandra
Default Password : cassandra


Connecting to Cassandra :-

root@node1:~# cqlsh -u cassandra node1
Password:
Connected to Test Cluster at node1:9042.
[cqlsh 5.0.1 | Cassandra 3.6 | CQL spec 3.4.2 | Native protocol v4]Use HELP for help.

To Check Cassandra Version :-

cassandra@cqlsh> SHOW VERSION ;
[cqlsh 5.0.1 | Cassandra 3.6 | CQL spec 3.4.2 | Native protocol v4]



Run from different host using (cqlsh client ) to connect with cassandra

In order to connect with cassandra with different machine you need to install cqlsh client on your system.  To install cqlsh you need to just download the tar archive of cassandra and extract it . I have extracted it under "/Users/ashu/Applications/dsc-cassandra-3.0.9" location.

# pwd
/Users/ashu/Applications/dsc-cassandra-3.0.9

# ls -ltr
total 832
-rw-r--r-- 1 ASHU 600 2730 Sep 30 2016 NOTICE.txt
-rw-r--r-- 1 ASHU 600 89963 Sep 30 2016 NEWS.txt
-rw-r--r-- 1 ASHU 600 11609 Sep 30 2016 LICENSE.txt
-rw-r--r-- 1 ASHU 600 312235 Sep 30 2016 CHANGES.txt
drwxr-xr-x 3 ASHU 600 102 Sep 30 2016 interface
drwxr-xr-x 5 ASHU 600 170 Sep 30 2016 doc
drwxr-xr-x 7 ASHU 600 238 Sep 30 2016 tools
-rwxr-xr-x 1 ASHU 600 2944 Sep 30 2016 switch_snappy
drwxr-xr-x 4 ASHU 600 136 Sep 30 2016 pylib
drwxr-xr-x 56 ASHU 600 1904 Sep 30 2016 lib
drwxr-xr-x 17 ASHU 600 578 Sep 30 2016 javadoc
drwxr-xr-x 28 ASHU 600 952 Sep 30 2016 bin
drwxr-xr-x 4 ASHU 600 136 Dec 5 14:43 logs
drwxr-xr-x 6 ASHU 600 204 Dec 5 14:43 data
drwxr-xr-x 17 ASHU 600 578 Dec 5 14:48 conf


You need to add extact_location/bin path in your PATH environment variable.

# echo $PATH
/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/Users/ashu/bin:/opt/local/bin:/usr/local/bin:/Users/ashu/Applications/dsc- cassandra-3.0.9/bin



Once path is added then then below command will list location of cqlsh.


which cqlsh
/Users/ashu/Applications/dsc-cassandra-3.0.9/bin/cqlsh 


No comments:

Post a Comment