Database
The database in Hive describes a collection of tables that are used for a similar purpose or belong to the same groups. If the database is not specified, the default
database is used and uses /user/hive/warehouse
in HDFS as its root directory. This path is configurable by the hive.metastore.warehouse.dir
property in hive-site.xml
. Whenever a new database is created, Hive creates a new directory for each database under /user/hive/warehouse
. For example, the myhivebook
database is located at /user/hive/datawarehouse/myhivebook.db
. In addition, DATABASE
has a name alias, SCHEMA
, meaning they are the same thing in HQL. The following is the major DDL for databases operations:
- Create the database/schema if it doesn't exist:
> CREATE DATABASE myhivebook; > CREATE SCHEMA IF NOT EXISTS myhivebook;
- Create the database with the location, comments, and metadata information:
> CREATE DATABASE IF NOT EXISTS myhivebook > COMMENT 'hive database demo' >...