Import and export schema in cassandra Import and export schema in cassandra database database

Import and export schema in cassandra


To export keyspace schema:

cqlsh -e "DESC KEYSPACE user" > user_schema.cql

To export entire database schema:

cqlsh -e "DESC SCHEMA" > db_schema.cql

To import schema open terminal at 'user_schema.cql' ('db_schema.cql') location (or you can specify the full path) and open cqlsh shell. Then use the following command to import keyspace schema:

source 'user_schema.cql'

To import full database schema:

source 'db_schema.cql'


If using cassandra-cli, you can use the 'show schema;' command to dump the whole schema. You can restrict to a specific keyspace by running 'use keyspace;' first.

You can store the output in a file, then import with 'cassandra-cli -f filename'.

If using cqlsh, you can use the 'describe schema' command. You can restrict to a keyspace with 'describe keyspace keyspace'.

You can save this to a file then import with 'cqlsh -f filename'.


For someone who comes in future, just to get ddl for schema/keyspace with "myschema" in "CassandraHost" server.

echo -e "use myschema;\nDESCRIBE KEYSPACE;\n" | cqlsh  CassandraHost > mySchema.cdl

and you can use following to import just DDL (without data):

cqlsh  CassandraNEWhost -f mySchema.cdl