Get the App
SLTechnology News&Howtos  ›  Database  › 

Cassandra two login methods cassandra-cli / csqlsh

Shulou Source: shulou.com Published: 2022-06-01 06:39:40 11月16日 Update

(1) cassandra-cli

The cassadnra-cli command is discarded in cassandra2.2. You can use cqlsh to log in and access cassandra later.

[tnuser@sht-sgmhadoopdn-02 cassandra] $cassandra-cli-h 172.16.101.59-p 9160

Connected to: "mycluster" on 172.16.101.59

Welcome to Cassandra CLI version 2.1.18

[default@unknown] create keyspace twissandra

With placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy'

And strategy_options = {replication_factor:1}

5200ec35-6f27-3f8f-a969-5f91b4308d40

[default@unknown] use twissandra

Authenticated to keyspace: twissandra

[default@twissandra] help create column family

[default@twissandra] create column family users with comparator = UTF8Type

8eadec66-a110-32b4-b873-5bfaaac2ddf5

[default@twissandra] update column family users with

Column_metadata =

[

{column_name: first, validation_class: UTF8Type}

{column_name: last, validation_class: UTF8Type}

{column_name: age, validation_class: UTF8Type, index_type: KEYS}

]

Ccdbe046-183a-307f-8e38-c1f44400f9fa

[default@twissandra] assume users keys as utf8

Assumption for column family 'users' added successfully.

# insert data

[default@twissandra] set users ['jsmith'] [' first'] = 'John'

[default@twissandra] set users ['jsmith'] [' last'] = 'Smith'

[default@twissandra] set users ['jsmith'] [' age'] = '38'

# insert data

[default@twissandra] get users ['jsmith']

= > (name=age, value=38, timestamp=1502764716526000)

= > (name=first, value=John, timestamp=1502764685559000)

= > (name=last, value=Smith, timestamp=1502764696653000)

# modify data values

[default@twissandra] set users ['jsmith'] [' first'] = 'Jack'

[default@twissandra] get users ['jsmith']

= > (name=age, value=38, timestamp=1502764716526000)

= > (name=first, value=Jack, timestamp=1502764821855000)

= > (name=last, value=Smith, timestamp=1502764696653000)

[default@twissandra] get users where age='38'

-

RowKey: jsmith

= > (name=age, value=38, timestamp=1502764716526000)

= > (name=first, value=Jack, timestamp=1502764821855000)

= > (name=last, value=Smith, timestamp=1502764696653000)

(2) cqlsh

[tnuser@sht-sgmhadoopdn-02 ~] $cqlsh-ucassandra-pcassandra localhost

# remote access:

[tnuser@sht-sgmhadoopnn-02 ~] $cqlsh 172.16.101.59

# View version

Cassandra@cqlsh:system > show version

[cqlsh 5.0.1 | Cassandra 3.11.1 | CQL spec 3.4.4 | Native protocol v4]

Cassandra@cqlsh:system > show host

Connected to Test Cluster at 127.0.0.1:9042.

# system.local table

Cassandra@cqlsh:system > select key,cluster_name,listen_address from system.local

Key | cluster_name | listen_address

-+-

Local | Test Cluster | 192.168.163.102

# create a keyspace:

Cqlsh > create keyspace mykeyspace with replication = {'class':'SimpleStrategy','replication_factor':1} AND durable_writes = true

# check the total number of keyspace:

Cqlsh > desc keyspaces

System_traces twissandra system mykeyspace

# View the details of the specified keyspace:

Cqlsh > desc mykeyspace

CREATE KEYSPACE mykeyspace WITH replication = {'class':' SimpleStrategy', 'replication_factor':' 1'} AND durable_writes = true

# enter a keyspace:

Cqlsh > use mykeyspace

# create a users table:

Cqlsh:mykeyspace > create table users (user_id int primary key,fname text,lname text)

Cqlsh:mykeyspace > desc tables

Users

# View users table information:

Cqlsh:mykeyspace > desc users

CREATE TABLE mykeyspace.users (

User_id int PRIMARY KEY

Fname text

Lname text

) WITH bloom_filter_fp_chance = 0.01,

AND caching ='{"keys": "ALL", "rows_per_partition": "NONE"}'

AND comment =''

AND compaction = {'class':' org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy'}

AND compression = {'sstable_compression':' org.apache.cassandra.io.compress.LZ4Compressor'}

AND dclocal_read_repair_chance = 0.1

AND default_time_to_live = 0

AND gc_grace_seconds = 864000

AND max_index_interval = 2048

AND memtable_flush_period_in_ms = 0

AND min_index_interval = 128,

AND read_repair_chance = 0.0

AND speculative_retry = '99.0 PERCENTILEE'

# insert data

Cqlsh:mykeyspace > insert into users (user_id,fname,lname) values

Cqlsh:mykeyspace > insert into users (user_id,fname,lname) values (1745)

Cqlsh:mykeyspace > insert into users (user_id,fname,lname) values

Cqlsh:mykeyspace > select * from users

User_id | fname | lname

-+-

1745 | john | smith

1744 | john | doe

1746 | john | jack

# create an index:

Cqlsh:mykeyspace > create index users_lname_idx on users (lname)

Cqlsh:mykeyspace > select * from users where lname='smith'

User_id | fname | lname

-+-

1745 | john | smith

Note:

If the data is created through cassandra-cli login and then viewed through cli, it may be incompatible:

Cqlsh:mykeyspace > desc twissandra

CREATE KEYSPACE twissandra WITH replication = {'class':' NetworkTopologyStrategy', 'datacenter1':' 1'} AND durable_writes = true

/ *

Warning: Table twissandra.users omitted because it has constructs not compatible with CQL (was created via legacy API). # warning here, it is not compatible

Approximate structure, for reference:

(this should not be used to reproduce this schema)

CREATE TABLE twissandra.users (

Key blob

Column1 text

Value blob

Age text

First text

Last text

PRIMARY KEY (key, column1)

) WITH COMPACT STORAGE

AND CLUSTERING ORDER BY (column1 ASC)

AND caching ='{"keys": "ALL", "rows_per_partition": "NONE"}'

AND comment =''

AND compaction = {'class':' org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy'}

AND compression = {'sstable_compression':' org.apache.cassandra.io.compress.LZ4Compressor'}

AND dclocal_read_repair_chance = 0.1

AND default_time_to_live = 0

AND gc_grace_seconds = 864000

AND max_index_interval = 2048

AND memtable_flush_period_in_ms = 0

AND min_index_interval = 128,

AND read_repair_chance = 0.0

AND speculative_retry = 'NONE'

CREATE INDEX users_age_idx ON twissandra.users (age)

, /

Cqlsh:mykeyspace > select * from twissandra.users

Key | column1 | value | age | first | last

-+-

0x6a736d697468 | age | 0x3338 | 38 | 38 | 38

0x6a736d697468 | first | 0x4a61636b | Jack | Jack | Jack

0x6a736d697468 | last | 0x536d697468 | Smith | Smith | Smith

Tags: Data login information command version index method Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Shulou Information vpn MySQL Redmi