Reputation: 5271
The problem that I am having is that I want to run the following command (and I can't):
cqlsh < cql_directory/cql_create_stuff.cql
Because I have not logged in to cqlsh.
So I logged in:
cqlsh -u 'my_username' -p 'my_super_secret_password'
and now I tried doing the command in cqlsh shell but It just responds with a syntax error.
Basically, how do I login into cqlsh and run an external CQL script in my file system?
Upvotes: 66
Views: 112506
Reputation: 11602
Assuming your filename is "tables.cql" and it is placed as: /files/tables.cql
;
cqlsh -f /files/tables.cql
Assuming the name of the Docker container that which running Cassandra is "cas" (keep in mind that you can also use the hash id of the docker container if there is no name assigned to it);
docker exec -it cas cqlsh -f /files/tables.cql
As stated on other answers, -u
and -p
options can be added in order to use the username/password combinations.
Upvotes: 5
Reputation: 501
This is for Window system
suppose you cassandra dir is C:\Program Files\DataStax-DDC\apache-cassandra\bin
Suppose directory where your .cql file OR cql query file is D:\ril\s\developement\new one\excel after parse\Women catalogue template.cql
Now follow below steps for importing cql file
And its Done.
Important Note:
Upvotes: 0
Reputation: 2291
Assuming that the path of the file with the CQL commands is /mydir/myfile.cql
, there are two ways:
If you are not logged in to cqlsh:
cqlsh -u 'my_username' -p 'my_password' -f /mydir/myfile.cql
If you are logged in to cqlsh:
SOURCE '/mydir/myfile.cql'
Notice the single quotation marks. The shorthand notation for $HOME
(for example, '~/mydir/myfile.cql'
) is also supported.
Both ways also work with relative paths (to the current directory).
Upvotes: 34
Reputation: 3374
Use the SOURCE
http://www.datastax.com/documentation/cql/3.1/cql/cql_reference/source_r.html
You can use -f
option as well to execute commands from file
http://www.datastax.com/documentation/cql/3.1/cql/cql_reference/cqlsh.html
Upvotes: 58