Monday, February 21, 2022

Running Cassandra in windows querying with cqlsh

 1- Download the cassandra apache-cassandra-3.11.6 from below url

https://archive.apache.org/dist/cassandra/3.11.6/
2- Make sure to have JDK and JRE above 8 version
3- Keep this environment variable in the system
CASSANDRA_HOME=C:\apache-cassandra-3.11.6
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_281
JRE_HOME=C:\Program Files\Java\jre1.8.0_281

4- Go to line # 356 and comment below lines from C:\apache-cassandra-3.11.6\conf\cassandra-env.ps1x`
$env:JVM_OPTS = “$env:JVM_OPTS -Djava.library.path=””$env:CASSANDRA_HOME\lib\sigar-bin”””
5- Open the cmd prompt with admin of poweshell with adming and go the installed directory and execute this
PS C:\apache-cassandra-3.11.6\bin> .\cassandra.bat
6- To check if the cassandra is runnning execute this command

C:\apache-cassandra-3.11.6\bin>cqlsh

WARNING: console codepage must be set to cp65001 to support utf-8 encoding on Windows platforms.
If you experience encoding problems, change your console codepage with ‘chcp 65001’ before starting cqlsh.

Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.11.6 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
WARNING: pyreadline dependency missing. Install to enable tab completion.
cqlsh>

You could use one of the following:

DbSchema (not free) :- https://www.dbschema.com/cassandra-designer-tool.html
DBeaver :- https://dbeaver.io/download/
RazorSQL :- https://razorsql.com/
Cassandra GUI Client :- https://github.com/Kindrat/cassandra-client

Lets create simple keyspace and table using below command to check our cassandra-3 is installed properly

1- CREATE KEYSPACE siddhu WITH replication = {‘class’:’SimpleStrategy’, ‘replication_factor’ : 3};

cqlsh> CREATE KEYSPACE siddhu WITH replication = {‘class’:’SimpleStrategy’, ‘replication_factor’ : 3};

2- cqlsh> DESCRIBE keyspaces;

system_schema system_auth system siddhu system_distributed system_traces

Now lets use this keyspace using below command

cqlsh> use siddhu;
cqlsh:siddhu>

Now lets create a table inside siddhu keyspace

1- CREATE TABLE sid_emp(
emp_id int PRIMARY KEY,
emp_name text,
emp_houseno varint
);

cqlsh:siddhu> CREATE TABLE sid_emp(
… emp_id int PRIMARY KEY,
… emp_name text,
… emp_houseno varint
… );
cqlsh:siddhu>

Lets query the Table sid_emp

cqlsh:siddhu> select * from sid_emp;

emp_id | emp_houseno | emp_name
——–+————-+———-

(0 rows)
cqlsh:siddhu>

In next tutorial we will see how to perform CRUD on cassandra DB.

No comments: