[英]Import and export schema in cassandra
如何从Cassandra或Cassandra cqlsh提示符下导入和导出模式?
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. 要导入模式,请在“ user_schema.cql”(“ db_schema.cql”)位置打开终端(或者您可以指定完整路径),然后打开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;' 如果使用cassandra-cli,则可以使用“显示模式”; command to dump the whole schema.
命令转储整个架构。 You can restrict to a specific keyspace by running 'use keyspace ;'
您可以通过运行'use keyspace ;'来限制特定的键空间 。 first.
第一。
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. 如果使用cqlsh,则可以使用“描述模式”命令。 You can restrict to a keyspace with 'describe keyspace keyspace '.
您可以使用'describe keyspace keyspace '来限制键空间 。
You can save this to a file then import with 'cqlsh -f filename '. 您可以将其保存到文件中,然后使用“ cqlsh -f filename ”导入。
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
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.