如何在不删除数据库目录的情况下将数据库拖放到配置单元中?
How can I drop database in hive without deleting database directory?
当我运行 drop database
命令时,spark 会删除hdfs 上的数据库目录及其所有子目录。我怎样才能避免这种情况?
简答:
除非您将数据库设置为仅包含存在于数据库 HDFS 目录之外的外部 table,否则如果不将所有数据复制到 HDFS 中的另一个位置,则无法实现此目的.
长答案:
来自以下网站:
https://www.oreilly.com/library/view/programming-hive/9781449326944/ch04.html
By default, Hive won’t permit you to drop a database if it contains tables. You can either drop the tables first or append the CASCADE keyword to the command, which will cause the Hive to drop the tables in the database first:
Using the RESTRICT keyword instead of CASCADE is equivalent to the default behavior, where existing tables must be dropped before dropping the database.
When a database is dropped, its directory is also deleted.
您可以在删除数据库之前将数据复制到另一个位置。我知道这很痛苦——但这就是 Hive 的运作方式。
如果您只是想删除 table 而不删除 table 的 HDFS 目录,这里有一个解决方案:Can I change a table from internal to external in hive?
删除外部 table 保留数据的 HDFS 位置。
在将它们转换为外部后将数据库删除级联到 tables 不会解决这个问题,因为数据库删除会影响数据库所在的整个 HDFS 目录。您仍然需要将数据复制到另一个位置。
如果您从头开始创建一个数据库,其中每个 table 内部都是外部的并且引用数据库 HDFS 目录之外的位置,则删除该数据库将保留数据。但是,如果您将其设置为数据当前位于数据库 HDFS 目录中,则您将没有此功能;这是您必须从头开始设置的东西。
当我运行 drop database
命令时,spark 会删除hdfs 上的数据库目录及其所有子目录。我怎样才能避免这种情况?
简答:
除非您将数据库设置为仅包含存在于数据库 HDFS 目录之外的外部 table,否则如果不将所有数据复制到 HDFS 中的另一个位置,则无法实现此目的.
长答案:
来自以下网站: https://www.oreilly.com/library/view/programming-hive/9781449326944/ch04.html
By default, Hive won’t permit you to drop a database if it contains tables. You can either drop the tables first or append the CASCADE keyword to the command, which will cause the Hive to drop the tables in the database first:
Using the RESTRICT keyword instead of CASCADE is equivalent to the default behavior, where existing tables must be dropped before dropping the database.
When a database is dropped, its directory is also deleted.
您可以在删除数据库之前将数据复制到另一个位置。我知道这很痛苦——但这就是 Hive 的运作方式。
如果您只是想删除 table 而不删除 table 的 HDFS 目录,这里有一个解决方案:Can I change a table from internal to external in hive?
删除外部 table 保留数据的 HDFS 位置。
在将它们转换为外部后将数据库删除级联到 tables 不会解决这个问题,因为数据库删除会影响数据库所在的整个 HDFS 目录。您仍然需要将数据复制到另一个位置。
如果您从头开始创建一个数据库,其中每个 table 内部都是外部的并且引用数据库 HDFS 目录之外的位置,则删除该数据库将保留数据。但是,如果您将其设置为数据当前位于数据库 HDFS 目录中,则您将没有此功能;这是您必须从头开始设置的东西。