Cassandra two ways to log in Cassandra-cli/csqlsh

Source: Internet
Author: User
Tags cassandra create index

(1) cassandra-cli

The CASSADNRA-CLI command is discarded in cassandra2.2, and later login access Cassandra can be used Cqlsh

[Email protected] cassandra]$ cassandra-cli-h 172.16.101.59-p 9160

Connected to: "Mycluster" on 172.16.101.59/9160

Welcome to Cassandra CLI version 2.1.18


[[email protected]] Create keyspace Twissandra;

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

and strategy_options = {replication_factor:1};

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


[[email protected]] use Twissandra;

Authenticated to Keyspace:twissandra



[[email protected]] help create column family;

[[email protected]] Create column family users with comparator = Utf8type;

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



[[email protected]] 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


[[email protected]] Assume users keys as UTF8;

Assumption for column family ' users ' added successfully.


#插入数据

[[email protected]] set users[' jsmith ' [' First ']= ' John ';

[[email protected]] set users[' jsmith ' [' Last ']= ' Smith ';

[[email protected]] set users[' jsmith ' [' Age ']= ' 38 ';


#插入数据

[[email protected]] Get users[' jsmith '];

= = (Name=age, value=38, timestamp=1502764716526000)

= = (Name=first, Value=john, timestamp=1502764685559000)

= = (Name=last, Value=smith, timestamp=1502764696653000)


#修改数据值

[[email protected]] set users[' jsmith ' [' First ']= ' Jack ';

[[email protected]] Get users[' jsmith '];

= = (Name=age, value=38, timestamp=1502764716526000)

= = (Name=first, value=jack, timestamp=1502764821855000)

= = (Name=last, Value=smith, timestamp=1502764696653000)



[[email protected]] 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

[Email protected] ~]$ Cqlsh-ucassandra-pcassandra localhost


#远程访问:

[Email protected] ~]$ Cqlsh 172.16.101.59


#查看版本

[Email protected]:system> show version;

[Cqlsh 5.0.1 | Cassandra 3.11.1 | CQL Spec 3.4.4 | Native Protocol V4]


[Email protected]:system> show host;

Connected to Test Cluster at 127.0.0.1:9042.


#system. Local table

[Email protected]:system> select key,cluster_name,listen_address from system.local;

Key | Cluster_Name | Listen_address

-------+--------------+-----------------

Local | Test Cluster | 192.168.163.102



#创建一个keyspace:

Cqlsh> Create Keyspace mykeyspace with replication = {' class ': ' Simplestrategy ', ' Replication_factor ': 1} and Durable_ Writes = TRUE;


#查看总共有哪些keyspace:

Cqlsh> desc keyspaces

System_traces Twissandra System Mykeyspace


#查看指定keyspace的详细信息:

Cqlsh> desc Mykeyspace

CREATE keyspace mykeyspace with replication = {' class ': ' Simplestrategy ', ' replication_factor ': ' 1 '} and durable_writes = True


#进入某个keyspace:

cqlsh> use Mykeyspace;


#创建一个users表:

Cqlsh:mykeyspace> CREATE TABLE users (user_id int primary key,fname text,lname text);

cqlsh:mykeyspace> desc tables;

Users


#查看users表信息:

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.0PERCENTILE ';


#插入数据

cqlsh:mykeyspace> INSERT into users (User_id,fname,lname) values (1744, ' John ', ' Doe ');

cqlsh:mykeyspace> INSERT into users (User_id,fname,lname) values (1745, ' John ', ' Smith ');

cqlsh:mykeyspace> INSERT into users (User_id,fname,lname) values (1746, ' John ', ' Jack ');

Cqlsh:mykeyspace> select * from users;

user_id | fname | LName

---------+-------+-------

1745 | John | Smith

1744 |   John | Doe

1746 |  John | Jack


#创建索引:

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


Attention:

If the data created through CASSANDRA-CLI login is then viewed through the CLI, it may not be compatible:

cqlsh:mykeyspace> desc Twissandra;

CREATE keyspace Twissandra with replication = {' class ': ' Networktopologystrategy ', ' datacenter1 ': ' 1 '} and Durable_writes = true;

/*

Warning:table Twissandra.users omitted because it had constructs not compatible with CQL (was created via Legacy API). # warnings are issued here, incompatible

Approximate structure, for reference:

(This should is 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

This article is from the "Darren memos" blog, be sure to keep this source http://darrenmemos.blog.51cto.com/10979687/1980944

Cassandra two ways to log in Cassandra-cli/csqlsh

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.