How to run cql files (.cql) from within cqlsh?

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


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).