First, start the Cassandra Client
Start Cassandra First, then run Bin\cassandra-cli.bat to start the client, the default hostname is Localhost,port 9160
F:\apache-cassandra-2.1. One-bin\bin>cassandra-clistarting Cassandra Clientorg.apache.thrift.transport.TTransportException:java.net.ConnectException: Connection Refused:connect at Org.apache.thrift.transport.TSocket.open (Tsocket.java:187) at Org.apache.thrift.transport.TFramedTransport.open (Tframedtransport.java:Bayi) at Org.apache.cassandra.thrift.TFramedTransportFactory.openTransport (Tframedtransportfactory.java: A) at Org.apache.cassandra.cli.CliMain.connect (Climain.java: the) at Org.apache.cassandra.cli.CliMain.main (Climain.java:239) caused by:java.net.ConnectException:Connection refused:connect at Java.net.DualStackPlainSocketImpl.connect 0 (Native Method) at Java.net.DualStackPlainSocketImpl.socketConnect (Unknown Source) at Java.net.AbstractPlai Nsocketimpl.doconnect (Unknown source) at Java.net.AbstractPlainSocketImpl.connectToAddress (Unknown source) a T Java.net.AbstractPlainSocketImpl.connect (Unknown Source) at Java.net.PlainSocketImpl.connect (Unknown source) At Java.net.SocksSocketImpl.connect (Unknown source) at Java.net.Socket.connect (Unknown source) at Org.apa Che.thrift.transport.TSocket.open (Tsocket.java:182) ... 4moreexception connecting to127.0.0.1/9160. Reason:connection Refused:connect. Welcome to Cassandra CLI version2.1. OneThe CLI isDeprecated and would be removedinchCassandra2.2. Consider Migratingto Cqlsh. CQL isFully backwards compatible with Thrift data; See http://www.datastax.com/dev/blog/thrift-to-Cql3type'Help ;'Or'?' forHelp . Type'quit;'Or'exit;'To quit.
Can see connection refused, if you encounter this problem first to check the configuration (specifically see I wrote the summary two before), and then see if Cassandra Start, Under WINDOW7, it is possible to initialize the data in the background after the startup is successful, so wait a little while before running Cassandra-cli.bat start the client, after the WINDOW8 start Cassandra do not close the window, window7 under the successful startup after the Windows Cassandra is still in the background Running, but closing the window under WINDOW8 is equivalent to shutting down the Cassandra, so window8 need to reopen a DOS window to run the Cassandra-cli.bat boot client.
You can also connect your own defined hostname and ports, such as: Cassandra-cli-h localhost-p 9160 or Cassandra-cli-hostname localhost-port 9160
On top of that we can see this sentence
is inch 2.2. Consider migrating to Cqlsh.
So the newer version wants to run the Cassandra client into the Cqlsh.
Ii. Introduction of Cassandra CLI
First of all, let me see what commands are in the CLI.
[default@unknown]?Getting around:? Display ThisHelp.help; Display ThisHelp.help<command>; Display command-specific help.exit; Exit ThisUtility.quit; Exit Thisutility. Commands:assume Apply Client side Validation.connect Connect to a Cassandra node.consiste Ncylevel sets Consisteny level forThe client to Use.count count columns or Super columns.create column family Add a column family To an existing keyspace.create keyspace Add a keyspace to the Cluster.del Delete a column, sup Er column or ROW.DECR decrements a counter column.describe cluster describe the cluster Configur Ation.describe describe a keyspace and its column families or column familyinchCurrent keyspace.drop column family remove a column family and its data.drop keyspace Remove a Keyspac E and its Data.drop index Remove an existing index fromspecific column.GetGet rows and columns.incr increments a counter column.list List rowsincha column family.SetSet columns.show API version show the server API version.show cluster name show the Cluster Name.show keyspaces Show all keyspaces and their column Families.show schema show a CLI scrip T to create keyspaces and column Families.truncate Drop the datainchA column family.update column family update the settings fora column family.update keyspace update the settings fora keyspace.use Switch to a keyspace.
Let's pick the main ones to talk about:
1. Connect
Connect Hostname/port;
2, Consistencylevel
More Information Reference http://www.doc88.com/p-495509829231.html
Since we are using a single node, we can set this value to one.
[defaultas isset'one'.
3. Create Keyspace
[default@unknown] Create keyspace keyspace1 with placement_strategy='simplestrategy' and strategy_options={replication_factor:1}; 6a9f1cd8-758d-3a9a-9f0a-e799b00bb159
Single-node replication_factor is set to 1 on the line.
4. Use
[default@unknown] use Keyspace1; Authenticated to Keyspace:keyspace1
5. Create Column Family
Column family is divided into standard and super two types, which by default are standard. Don't know, you can first understand the Cassandra data storage structure.
To create a standard type:
[default@keyspace1] Create column family standardfamily with comparator=utf8type;b7f2a26b- 1e36-31e0-a7c2-7d32daf041fd
All the column in a key is sorted by its name, and comparator is the set sort type. (for sorting, please consult yourself)
To create a super type:
[default@keyspace1] Create column family superfamily with comparator ='Super' ; 2bf4b959-6199-321B-8E56-C8CB2F653AE1
In super type, comparator is sorted by all supercolumn keys, Subcomparator is sorted by the name of all column in Supercolumn.
6. Set
Insert data of standard type:
[defaultset standardfamily['key1'] ['cloumnName1 ' ' columnValue1 ' 'columnValue1' as hex bytes
We can see that cannot parse, this time need to call the ASCII () function, UTF8 () function and other functions to set the data type, Cassandra data type has bytes, integer, long, int, lexicaluuid, Timeuuid, UTF8, ASCII, double, countercolumn.
[defaultset standardfamily['key1'] ['cloumnName1 '] = ASCII ('columnValue1'key1' as Hex bytes
You can see that key cannot be parsed, in fact key,column_name,column_value are required for function parsing.
[defaultset Standardfamily[utf8 ('key1')][utf8 (' columnName1')] = UTF8 ('columnValue1'52 msec (s).
Successfully inserted, but this is obviously cumbersome, we can use assume to set the data type.
7, assume
Format: Assume column family validator/comparator/keys/sub_comparator as type;
[defaultAs for'standardfamily' added successfully.
Set the data type of key to UTF8.
[defaultAs for'standardfamily' added Successfully.
Set the data type of value to UTF8.
As for Comparator/sub_comparator, it is the type of the specified sort. (the sort type is mentioned earlier)
[defaultset standardfamily['key2'] ['columnName2 ' ' columnValue2 ' 1.85 msec (s).
This can be inserted directly if the sort type is also set to name (hint: If COLUMN_NAME does not set the sort type, column_name is still required to parse the function)
And the authentication type set by assume is invalidated after shutting down the server, so our permanent method is to modify the settings of column family directly, see the following update.
8. Update Column Family
[default= utf8type and Default_validation_class = utf8type;fe850dbb-c170-3639- 846d-2ce3ef975462
This setting is permanently saved.
9, describe
Let's look at the configuration of the standradfamily.
[default@keyspace1] describe standardfamily; WARNING:CQL3 tables is intentionally omitted from 'describe'output. See https://issues.apache.org/jira/browse/cassandra-4377 for details.columnfamily:standardfamily Key Validation Class:org.apache.cassandra.db.marshal.UTF8Type Default Colu MN value Validator:org.apache.cassandra.db.marshal.UTF8Type Cells sorted BY:ORG.APACHE.CASSANDRA.DB.MARSHAL.UTF8TYP E GC Grace seconds:864000compaction min/max Thresholds:4/ +Read Repair chance:0.0DC Local Read repair chance:0.1caching:keys_only Default time to live:0Bloom Filter FP chance:defaultIndex interval:defaultSpeculative Retry:none Built indexes: [] compaction Strategy:org.apache.cassandra.db.compaction.Size Tieredcompactionstrategy Compression Options:sstable_compression:org.apache.cassandra.io.compress.LZ4Compres Sor
You can see that our settings are in effect.
10. Get
Gets the value corresponding to key
[defaultget standardfamily['key1']; = = (Name=columnname1, value=columnvalue1, timestamp=14483676336460001 193 msec (s).
Gets the value corresponding to the COLUMN_NAME key
[defaultget standardfamily['key1'] ['columnName1 ' ]; = = (Name=columnname1, value=columnvalue1, timestamp=1448367633646000193 msec (s).
11. List
Gets all the data in a column family, or limits the number of queries, by default 100
[default@keyspace1] List standardfamily; UsingdefaultLimit of -UsingdefaultCell Limit of --------------------RowKey:3= (name=3, value=3, timestamp=1448369924110000)-------------------Rowkey:key1= = (Name=columnname1, value=columnvalue1, timestamp=1448367633646000)-------------------RowKey:1= (name=1, value=1, timestamp=1448368544230000)-------------------Rowkey:key2= (name=2, Value=columnvalue2, timestamp=1448369767734000)= = (Name=columnname2, value=columnvalue2, timestamp=1448369748230000)4Rows returned.elapsed Time: themsec (s).
[[email protected]] list standardfamily limit 1; Using Default cell limit of-------------------rowkey:3=> (name=3, value=3, timestamp=1448369924110000) 1 Row retur Ned. Elapsed time:24 msec (s).
It can be seen that key is sorted according to Cassandra's own mechanism, but column or supercolumn can be sorted by their own definition of type.
PS: The rest will not be described in detail
Summary of basic operation--cassandra of CASSANDRA-CLI (iii)