Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cqlsh equivalent to mysql -e

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

like image 821
pcalcao Avatar asked Jun 11 '14 10:06

pcalcao


People also ask

Is Cassandra same as MySQL?

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.

Is CQL same as SQL?

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.

Why is Cassandra faster than MySQL?

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.

What is Cqlsh?

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.


1 Answers

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.

like image 72
Aaron Avatar answered Sep 30 '22 11:09

Aaron