首页 > 其他分享 >cassandra常用命令

cassandra常用命令

时间:2022-12-20 16:56:32浏览次数:34  
标签:20 08 system hadoop cqlsh 常用命令 store cassandra

一、capture用于捕获命令的输出并将其添加到文件

hadoop@datax ~]$ touch 1.txt
[hadoop@datax ~]$ cqlsh
Connected to Test Cluster at 127.0.0.1:9042
[cqlsh 6.0.0 | Cassandra 4.0.0 | CQL spec 3.4.5 | Native protocol v5]
Use HELP for help.
cqlsh> use store
... ;
cqlsh:store> CAPTURE '/home/hadoop/1.txt'
Now capturing query output to '/home/hadoop/1.txt'.
cqlsh:store> select * from shopping_cart ;
cqlsh:store> CAPTURE off

cqlsh:store> exit
[hadoop@datax ~]$ cat 1.txt

userid | item_count | last_update_timestamp
--------+------------+---------------------------------
1234 | 5 | 2022-12-20 08:20:18.813000+0000
9876 | 2 | 2022-12-20 08:20:17.765000+0000

(2 rows)

 

二、CONSISTENCY显示当前的一致性级别,或设置新的一致性级别

 

cqlsh> CONSISTENCY
Current consistency level is ONE.

cqlsh> CONSISTENCY
Current consistency level is TWO.

三、Copy将数据从cassandra复制到文件并从中复制

cqlsh:store> select * from shopping_cart ;

userid | item_count | last_update_timestamp
--------+------------+---------------------------------
1234 | 5 | 2022-12-20 08:20:18.813000+0000
9876 | 2 | 2022-12-20 08:20:17.765000+0000

(2 rows)
cqlsh:store> copy shopping_cart(userid, item_count , last_update_timestamp) to '/home/hadoop/2.txt'
... ;   #这里表后面加不加字段不影响输出结果
Using 1 child processes

Starting copy of store.shopping_cart with columns [userid, item_count, last_update_timestamp].
Processed: 2 rows; Rate: 17 rows/s; Avg. rate: 17 rows/s
2 rows exported to 1 files in 0.122 seconds.

cqlsh:store> exit
[hadoop@datax ~]$ cat 2.txt
1234,5,2022-12-20 08:20:18.813+0000
9876,2,2022-12-20 08:20:17.765+0000

 

四、describe描述casscadra及其对像的当前集群

 

[hadoop@datax ~]$ cqlsh
Connected to Test Cluster at 127.0.0.1:9042
[cqlsh 6.0.0 | Cassandra 4.0.0 | CQL spec 3.4.5 | Native protocol v5]
Use HELP for help.
cqlsh> DESCRIBE cluster

 

Cluster: Test Cluster
Partitioner: Murmur3Partitioner
Snitch: DynamicEndpointSnitch

 

cqlsh> DESCRIBE KEYSPACEs;

store system_auth system_schema system_views
system system_distributed system_traces system_virtual_schema

cqlsh> DESCRIBE tables;

Keyspace store
--------------
shopping_cart

Keyspace system
---------------
available_ranges paxos size_estimates
available_ranges_v2 peer_events sstable_activity
batches peer_events_v2 table_estimates
built_views peers transferred_ranges
compaction_history peers_v2 transferred_ranges_v2
"IndexInfo" prepared_statements view_builds_in_progress
local repairs

Keyspace system_auth
--------------------
network_permissions role_members roles
resource_role_permissons_index role_permissions

Keyspace system_distributed
---------------------------
parent_repair_history repair_history view_build_status

Keyspace system_schema
----------------------
aggregates dropped_columns indexes tables types
columns functions keyspaces triggers views

Keyspace system_traces
----------------------
events sessions

Keyspace system_views
---------------------
caches internode_inbound rows_per_read
clients internode_outbound settings
coordinator_read_latency local_read_latency sstable_tasks
coordinator_scan_latency local_scan_latency system_properties
coordinator_write_latency local_write_latency thread_pools
disk_usage max_partition_size tombstones_per_read

Keyspace system_virtual_schema
------------------------------
columns keyspaces tables

 

cqlsh> use store;
cqlsh:store> DESCRIBE TABLE shopping_cart;

CREATE TABLE store.shopping_cart (
userid text PRIMARY KEY,
item_count int,
last_update_timestamp timestamp
) WITH additional_write_policy = '99p'
AND bloom_filter_fp_chance = 0.01
AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
AND cdc = false
AND comment = ''
AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
AND compression = {'chunk_length_in_kb': '16', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1.0
AND default_time_to_live = 0
AND extensions = {}
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 = 'BLOCKING'
AND speculative_retry = '99p';

 

五、expand扩展输出

 

cqlsh> EXPAND on ;
Now Expanded output is enabled
cqlsh> use store
... ;
cqlsh:store> select * from shopping_cart ;

 

@ Row 1
-----------------------+---------------------------------
userid | 1234
item_count | 5
last_update_timestamp | 2022-12-20 08:20:18.813000+0000

 

@ Row 2
-----------------------+---------------------------------
userid | 9876
item_count | 2
last_update_timestamp | 2022-12-20 08:20:17.765000+0000

 

(2 rows)

 

六、source可以在文件中执行命令

 

[hadoop@datax ~]$ cat t2.txt
use store;
select * from shopping_cart;
[hadoop@datax ~]$ cqlsh
Connected to Test Cluster at 127.0.0.1:9042
[cqlsh 6.0.0 | Cassandra 4.0.0 | CQL spec 3.4.5 | Native protocol v5]
Use HELP for help.
cqlsh> source '/home/hadoop/'
.bash_history .bash_logout .bash_profile .bashrc .cache/ .cassandra/ .pki/ .ssh/ 1.txt 2.txt t2.txt
cqlsh> source '/home/hadoop/t2.txt'

 

userid | item_count | last_update_timestamp
--------+------------+---------------------------------
1234 | 5 | 2022-12-20 08:20:18.813000+0000
9876 | 2 | 2022-12-20 08:20:17.765000+0000

 

(2 rows)

 

标签:20,08,system,hadoop,cqlsh,常用命令,store,cassandra
From: https://www.cnblogs.com/chinaops/p/16994596.html

相关文章

  • git常用命令记录
    gitcheckoutbranchName切换分支gitswitchbranchName切换分支gitcheckout-bnewBranchName从当前分支拉去代码创建分支,并切换到新分支git......
  • Kubernetes(k8s) kubectl cluster-info常用命令
    kubectl在$HOME/.kube目录中查找一个名为config的配置文件。可以通过设置KUBECONFIG环境变量或设置--kubeconfig参数来指定其它kubeconfig文件。本文主要介绍K......
  • Kubernetes(k8s) kubectl certificate常用命令
    kubectl在$HOME/.kube目录中查找一个名为config的配置文件。可以通过设置KUBECONFIG环境变量或设置--kubeconfig参数来指定其它kubeconfig文件。本文主要介绍K......
  • Anaconda常用命令
    首先有什么问题可以去找官方文档condacreate—conda4.14.0.post39+de3db7f75documentation环境管理查看conda环境管理命令帮助信息condacreate--help创建......
  • Kubernetes(k8s) kubectl rollout status常用命令
    kubectl在$HOME/.kube目录中查找一个名为config的配置文件。可以通过设置KUBECONFIG环境变量或设置--kubeconfig参数来指定其它kubeconfig文件。本文主要介绍K......
  • redis常用命令之string&list
    redis常用操做stringkey操作string<key:value>setnamejohngetnamelistsetnx<keyvalue>setnxgendermale(分布式锁)getgendersetnxgoods_1111delgoods_1ge......
  • git使用Git 常用命令
    Git常用命令 仓库 #在当前目录新建一个Git代码库$gitinit#新建一个目录,将其初始化为Git代码库$gitinit[project-name]#下载一个项目和它的整个代码......
  • postgreSQL常用命令
     --建表案例CREATETABLEgas_use_test(idserialPRIMARYKEYNOTNULL,tenantIdintegerNOTNULL,meterNovarchar(255)uniqueNOTNULL,......
  • Kubernetes(k8s) kubectl rollout resume常用命令
    kubectl在$HOME/.kube目录中查找一个名为config的配置文件。可以通过设置KUBECONFIG环境变量或设置--kubeconfig参数来指定其它kubeconfig文件。本文主要介绍K......
  • Linux 常用命令整理
    【常用命令】  查询当前时间:date  修改时间:tzselect #根据提示输入编号  显示当前绝对路径:pwd  重启系统:reboot  在指定文件中查找某内容:grep"某......