Hive基本使用——命令行

基本使用

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后面内容为字段描述信息
    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;
    结果:
    OK
    testtable
    Time taken: 0.023 seconds, Fetched: 1 row(s)
  2. 查看所有表
    hive> show tables;
  3. 查看表信息
    hive> desc studenttable;
    OK
    |name | string | name value |
    |sex | string | sex value |
    |age | string | age value |
    –这里面有一个字段data,是string类型的,描述信息comment是“d comment”。
  4. 查看扩展描述信息
    hive> describe formatted studenttable;
    结果:
    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
  5. 删除表
    hive> drop table testtable;
  6. 表加载数据
    hive> load data local inpath '/data/apps/test/zhangwenchao/data/data.txt' into table studenttable;
    结果:
    Loading data to table zwctest.studenttable
    Table zwctest.studenttable: [numFiles=1, totalSize=2117]
    OK
    Time taken: 0.659 seconds
  7. 查看数据
    hive>select * from testtable;

你可能感兴趣的:(大数据,hadoop,hive)