I'm trying to create a small shell script where it would be very handy for me to run a command directly from the command line via cqlsh.
In MySQL I could do something like:
mysql -u root -e "show databases;"
Is there a cqlsh equivalent to -e
, or is the closest equivalent putting whatever commands I want to run in a file and use -f
?
Thanks
MySQL, as you know, is an RDBMS (Relational Database Management System). Cassandra, however, is a NoSQL database. This means that MySQL will follow more of a master/worker architecture, while Cassandra follows peer-to-peer architecture.
CQL query language is a NoSQL interface that is intentionally similar to SQL, providing users who are comfortable with relational databases a familiar language that ultimately lowers the barrier of entry to Apache Cassandra.
Major reason behind Cassandra's extremely faster writes is its storage engine. Cassandra uses Log-structured merge trees, whereas traditional RDBMS uses B+ Trees as underlying data structure. If you notice "B", you will find that Oracle just like MySQL has to read before write.
cqlsh is a command-line interface for interacting with Cassandra using CQL (the Cassandra Query Language). It is shipped with every Cassandra package, and can be found in the bin/ directory alongside the cassandra executable.
For just a one-shot command, cqlsh
4.1.1 also has a -e
option:
$cqlsh -e 'desc keyspaces' -u myusername -p mypassword localhost
branch stackoverflow products system_auth
customers system branches system_traces
If you have something complicated, like a multi-line sequence of commands, then the -f
option on cqlsh
should be what you want to do. To demo, I'll create a simple cql script file called descTables.cql
which looks like this:
$ cat descTables.cql
use stackoverflow;
desc tables;
Now, I'll invoke that cql script with cqlsh -f
:
$cqlsh -f descTables.cql -u myusername -p mypassword localhost
datasimple items
FYI- It looks like the most-recent version of 2.0 has cqlsh
4.1.1, which has the -e
flag. On one of my instances, I have 4.1.0 and the -e
option is not available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With