database cassandra 中的导入和导出模式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16440606/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Import and export schema in cassandra
提问by vpggopal
How to import and export schema from Cassandra or Cassandra cqlsh prompt?
如何从 Cassandra 或 Cassandra cqlsh 提示符导入和导出模式?
回答by Raman Yelianevich
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:
在'user_schema.cql' ('db_schema.cql') 位置导入模式打开终端(或者您可以指定完整路径)并打开 cqlsh shell。然后使用以下命令导入密钥空间架构:
source 'user_schema.cql'
To import full database schema:
要导入完整的数据库架构:
source 'db_schema.cql'
回答by Richard
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.
如果使用 cassandra-cli,则可以使用“show schema;” 命令转储整个模式。您可以通过运行“use keyspace;”来限制特定的键空间 第一的。
You can store the output in a file, then import with 'cassandra-cli -f filename'.
您可以将输出存储在文件中,然后使用“cassandra-cli -f filename”导入。
If using cqlsh, you can use the 'describe schema' command. You can restrict to a keyspace with 'describe keyspace keyspace'.
如果使用 cqlsh,您可以使用“describe schema”命令。您可以使用“describe keyspace keyspace”来限制键空间。
You can save this to a file then import with 'cqlsh -f filename'.
您可以将其保存到文件中,然后使用“cqlsh -f filename”导入。
回答by dillip pattnaik
For someone who comes in future, just to get ddl for schema/keyspace with "myschema" in "CassandraHost" server.
对于将来来的人,只是为了在“CassandraHost”服务器中使用“myschema”获取模式/键空间的ddl。
echo -e "use myschema;\nDESCRIBE KEYSPACE;\n" | cqlsh CassandraHost > mySchema.cdl
and you can use following to import just DDL (without data):
您可以使用以下内容仅导入 DDL(无数据):
cqlsh CassandraNEWhost -f mySchema.cdl
回答by rouble
Everything straight from the command line. No need to go into cqlsh.
一切都直接来自命令行。无需进入 cqlsh。
Import schema (.cql file):
导入架构(.cql 文件):
$ cqlsh -e "SOURCE '/path/to/schema.cql'"
Export keyspace:
导出密钥空间:
$ cqlsh -e "DESCRIBE KEYSPACE somekeyspace" > /path/to/somekeyspace.cql
Export database schema:
导出数据库架构:
$ cqlsh -e "DESCRIBE SCHEMA" > /path/to/schema.cql

