多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
**1. 创建 hivebook 数据库** ```sql 0: jdbc:hive2://hadoop101:10000> create database hivebook; 0: jdbc:hive2://hadoop101:10000> create database if not exists hivebook; -- location 指定数据在hdfs上的存储位置 0: jdbc:hive2://hadoop101:10000> create database if not exists hivebook location '/home/hive'; ``` **2. 选用 hivebook 数据库** ```sql 0: jdbc:hive2://hadoop101:10000> use myhivebook; ``` **3. 查看 hivebook 数据库的描述** ```sql -- (1)方式1 0: jdbc:hive2://hadoop101:10000> desc database hivebook; +-----------+----------+----------------------------------------------------+-------------+-------------+-------------+--+ | db_name | comment | location | owner_name | owner_type | parameters | +-----------+----------+----------------------------------------------------+-------------+-------------+-------------+--+ | hivebook | | hdfs://hadoop101:9000/home/hadoop/hive/warehouse/hivebook.db | root | USER | | +-----------+----------+----------------------------------------------------+-------------+-------------+-------------+--+ -- (2)方式2 0: jdbc:hive2://hadoop101:10000> describe database hivebook; +-----------+----------+----------------------------------------------------+-------------+-------------+-------------+--+ | db_name | comment | location | owner_name | owner_type | parameters | +-----------+----------+----------------------------------------------------+-------------+-------------+-------------+--+ | hivebook | | hdfs://hadoop101:9000/home/hadoop/hive/warehouse/hivebook.db | root | USER | | +-----------+----------+----------------------------------------------------+-------------+-------------+-------------+--+ -- (3)方式3 0: jdbc:hive2://hadoop101:10000> desc database extended hivbook; +-----------+----------+----------------------------------------------------+-------------+-------------+-------------+--+ | db_name | comment | location | owner_name | owner_type | parameters | +-----------+----------+----------------------------------------------------+-------------+-------------+-------------+--+ | hivebook | | hdfs://hadoop101:9000/home/hadoop/hive/warehouse/hivebook.db | root | USER | | +-----------+----------+----------------------------------------------------+-------------+-------------+-------------+--+ ``` **4. 改变 hivebook 数据库的拥有者为 root** ```sql 0: jdbc:hive2://hadoop101:10000> alter database hivebook set owner user root; ``` 改变前为anonymouns拥有 ![](https://img.kancloud.cn/bb/66/bb662d34b388cd0c15da9871a37a7f78_1456x238.png) 改变后为root拥有。 <br/> **5. 删除 hivebook2 数据库** ```sql -- (1)方式1删除:当数据库为空时才能删除 0: jdbc:hive2://hadoop101:10000> drop database if exists hivebook2; -- (2)方式2删除:无论数据库是否为空,强制删除 0: jdbc:hive2://hadoop101:10000> drop database if exists hivebook2 cascade; ``` **6. 模糊查询数据库** ```sql 0: jdbc:hive2://hadoop101:10000> show databases like 'hive*'; +----------------+--+ | database_name | +----------------+--+ | hivebook | | hivedb | | hivedb2 | +----------------+--+ ``` **7. 查看当前所使用的数据库** ```sql 0: jdbc:hive2://hadoop101:10000> select current_database(); +-----------+--+ | _c0 | +-----------+--+ | hivebook | +-----------+--+ ```