一、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