Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed explanation of Cassandra CLI command

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Detailed explanation of Cassandra Shell command

Logincqlsh 172.20.101.252-u cassandra-p cassandra Connected to cn-engage-dev at 172.20.101.252 cqlsh 9042. [cqlsh 5.0.1 | Cassandra 3.11.4 | CQL spec 3.4.4 | Native protocol v4] create a KeyspaceCREATE KEYSPACE WITH detail: CREATE KEYSPACE "KeySpace Name" WITH replication = {'class':' Strategy name', 'replication_factor':' No.Of replicas'} AND durable_writes = 'Boolean value'

The CREATE KEYSPACE statement has two attributes: replication and durable_writes.

Replication

Policies supported by replication

Policy name describes a simple policy (SimpleStrategy) specifies a simple replication factor for the cluster. Network Topology Policy (NetworkTopologyStrategy) uses this option to set replication factors individually for each data center. Legacy network topology strategies use this option to set replication factors individually for each data center. Durable_writes

By default, the durable_writes property of the table is set to true, but it can be set to false.

The durable_writes parameter is used to set whether to write commit log when writing data. If set to false, the write request will not write commit log and there is a risk of data loss. This parameter defaults to true, that is, to write commit log, the production system should set this parameter to true.

Example:

Create a KeySpace called ptmind_test, use the Network Topology Strategy (NetworkTopologyStrategy), make two copies in Datacenter 1, and turn on write commit log.

Create cassandra@cqlsh > create keyspace ptmind_test with replication = {'class':'NetworkTopologyStrategy','dc1':2} and durable_writes = true; to view the creation syntax cassandra@cqlsh > desc keyspace ptmind_test;CREATE KEYSPACE ptmind_test WITH replication = {' class':'NetworkTopologyStrategy','dc1':'2'} AND durable_writes = true

# Capture

This command captures the output of the command and adds it to the file. For example, look at the following code, which captures the output to a file named Outputfile.

When we type any command in the terminal, the output will be captured by the given file. The following is a snapshot of the commands used and the output file.

Cassandra@cqlsh > capture'. / cassandra.out'Now capturing query output to'. / cassandra.out'. Turn off capture: cqlsh:cqlsh > capture off;Consistency

This command displays the current conformance level, or sets a new conformance level.

Consistency can understand Consistency Level for read and write operations

The consistency level of the write operation specifies the number of replica that the write operation must ensure that the write operation has completed successfully before notifying the client that the request was successful.

Details: https://blog.51cto.com/michaelkang/2415292

Show current level CONSISTENCYcassandra@cqlsh > CONSISTENCY Current consistency level is ONE.Describe

This command describes the current cluster of Cassandra and its objects. The variants of this command are described below.

Describe cluster-this command provides information about the cluster.

Cassandra@cqlsh > DESCRIBE cluster;Cluster: cn-engage-devPartitioner: Murmur3PartitionerDescribe Keyspaces

-this command lists all key spaces in the cluster. The usage of this command is given below.

Cassandra@cqlsh > DESCRIBE keyspaces;system_schema system system_distributedsystem_auth ptmind_test system_traces create tables create a table with Set type columns CREATE TABLE users (user_id text PRIMARY KEY, first_name text, last_name text, emails set); insert data INSERT INTO users (user_id, first_name, last_name, emails) VALUES ('2records,' kevin', 'kevin', {' kevin@ptmind.com', 'kevin@gmail.com'}); Describe tables

-this command lists all tables in the key space. The usage of this command is given below.

Cassandra@cqlsh:ptmind_test > Describe tables;users emp ptempDescribe tables

-this command provides a description of the table. The usage of this command is given below.

Cqlsh:cqlsh > describe table emp;Describe tables

This command is used to describe user-defined data types. The usage of this command is given below.

Cassandra@cqlsh:ptmind_test > DESCRIBE table users CREATE TABLE ptmind_test.users (user_id text PRIMARY KEY, emails set, first_name text, last_name text) WITH bloom_filter_fp_chance = 0.01AND caching = {'keys':' ALL', 'rows_per_partition':' NONE'} AND comment =''AND compaction = {' class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy',' max_threshold': '32' 'min_threshold':' 4'} AND compression = {'chunk_length_in_kb':' 64' 'class':' org.apache.cassandra.io.compress.LZ4Compressor'} AND crc_check_chance = 1. 0 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 PERCENTILE' Describe Types

This command lists all user-defined data types. The usage of this command is given below. Suppose there are two user-defined data types: users and test_tables.

Cassandra@cqlsh:ptmind_test > DESCRIBE TYPES;users test_tablesCopy

This command copies data from Cassandra to a file and from it. Here is an example of copying a table named emp to the file myfile.

Cassandra@cqlsh:ptmind_test > COPY users (user_id, first_name, last_name, emails) TO 'kevinfile';Using 3 child processesStarting copy of ptmind_test.users with columns [user_id, first_name, last_name, emails]. Processed: 2 rows; Rate: 1 rows/s; Avg. Rate: 1 rows/s2 rows exported to 1 files in 1.472 seconds. Verification: [root@kubm-01 ~] # more kevinfile 2 Expand Kevin, "{'kevin@gmail.com',' kevin@ptmind.com'}" frodo,Frodo,Baggins, "{'baggins@gmail.com',' frankbaggins.com'}" Expand

This command is used to expand output. You must open the expand command before using this command. The usage of this command is given below.

Cqlsh:cqlsh > expand on;cqlsh:cqlsh > select * from users;cassandra@cqlsh:ptmind_test > select * from users @ Row 1Mushroom user_id | 2 emails | {'kevin@gmail.com' 'kevin@ptmind.com'} first_name | kevin last_name | kevin@ Row 2 kevin last_name-(2 rows) use the following command to turn off the deployment option. Cqlsh:cqlsh > expand off;Disabled Expanded output.Source

With this command, you can execute the command in a file. Suppose our input file is as follows:

You can then execute the file that contains the command, as shown below.

[root@kubm-01 ~] # pwd/ root [root @ kubm-01 ~] # more cqshell.source select * from users; login execution Cassandra@cqlsh:ptmind_test > SOURCE'/ root/cqshell.source' user_id | emails | first_name | last_name-+--+-+- -2 | {'kevin@gmail.com' 'kevin@ptmind.com'} | kevin | kevin frodo | {' baggins@gmail.com', 'frankbaggins.com'} | Frodo | Baggins (2 rows)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report