首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >[981]Hive基本使用——命令行

[981]Hive基本使用——命令行

作者头像
周小董
发布2021-05-18 11:14:53
发布2021-05-18 11:14:53
8260
举报
文章被收录于专栏:python前行者python前行者

基本使用

Hive 用户接口主要有三个:命令行(CLI),客户端(Client) 和 Web界面(WUI)。其中最常用的是 CLI,启动的时候,会同时启动一个 Hive 服务。Client 是 Hive 的客户端,用户连接至 Hive Server。在启动 Client 模式的时候,需要指出 Hive Server 所在节点,并且在该节点启动 Hive Server。 WUI 是通过浏览器访问 Hive的Web工具

这里介绍Hive命令行的一个基本使用

注意:hive命令行语句后面一定要加分号

库操作

  1. 创建数据库 hive> create database zwctest;
  2. 查看数据库 hive> show databases;
  3. 切换数据库 hive>use database_name;
  4. 删除数据库 hive> drop database if exists database_name;

表操作

  1. 创建表:创建一个外部表,表字段有name,sex,age,comment后面内容为字段描述信息
代码语言:javascript
复制
hive> create external table if not exists studenttable(
name string comment 'name value',
sex string comment 'sex value',
age string comment 'age value')
row format delimited
fields terminated by '\t'
lines terminated by '\n'
stored as textfile;

结果:

代码语言:javascript
复制
OK
testtable
Time taken: 0.023 seconds, Fetched: 1 row(s)

  1. 查看所有表:hive> show tables;

  1. 查看表信息:hive> desc studenttable;
代码语言:javascript
复制
OK
|name | string | name value |
|sex | string | sex value |
|age | string | age value |

这里面有一个字段data,是string类型的,描述信息comment是“d comment”。

  1. 查看扩展描述信息:hive> describe formatted studenttable;

结果:

代码语言:javascript
复制
OK
#col_name data_type comment
name string name value
sex string sex value
age string age value
#Detailed Table Information
Database: zwctest
Owner: root
CreateTime: Sun Oct 23 17:52:38 CST 2016
LastAccessTime: UNKNOWN
Protect Mode: None
Retention: 0
Location: hdfs://test1:8020/user/hive/warehouse/zwctest.db/studenttable
Table Type: EXTERNAL_TABLE
Table Parameters:
EXTERNAL TRUE
transient_lastDdlTime 1477216358
# Storage Information
SerDe Library: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
InputFormat: org.apache.hadoop.mapred.TextInputFormat
OutputFormat: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
Compressed: No
Num Buckets: -1
Bucket Columns: []
Sort Columns: []
Storage Desc Params:
field.delim \t
line.delim \n
serialization.format \t
Time taken: 0.055 seconds, Fetched: 31 row(s)

注:desc为简写,可写全拼describe

  1. 删除表:hive> drop table testtable;

  1. 表加载数据
代码语言:javascript
复制
hive> load data local inpath '/data/apps/test/zhangwenchao/data/data.txt' into table studenttable;

结果:

代码语言:javascript
复制
Loading data to table zwctest.studenttable
Table zwctest.studenttable: [numFiles=1, totalSize=2117]
OK
Time taken: 0.659 seconds

  1. 查看数据:hive>select * from testtable;

来源:https://blog.csdn.net/xiaolei565/article/details/107939678

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021/05/16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 基本使用
  • 库操作
  • 表操作
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档