1.Hive非交互模式常用命令:

  1) hive -e:从命令行执行指定的HQL,不需要分号:

% hive -e 'select * from dummy' > a.txt

  2) hive –f: 执行HQL脚本

% hive -f /home/my/hive-script.sql  --hive-script.sql是hql脚本文件

  3) hive -i:进入Hive交互Shell时候先执行脚本中的HQL语句

% hive -i /home/my/hive-init.sql 

  4) hive -v:冗余verbose模式,额外打印出执行的HQL语句

  5) hive -S:静默Slient模式,不显示转化MR-Job的信息,只显示最终结果

% hive -S -e ‘select * from student’

  6)hive --hiveconf <property=value>:使用给定属性的值

$HIVE_HOME/bin/hive --hiveconf mapred.reduce.tasks= //启动时,配置reduce个数2(只在此session中有效)

  7)hive --service serviceName:启动服务

  8)hive [--database test]:进入CLI交互界面,默认进入default数据库。加上[]内容直接进入test数据库。

%hive --database test

3.Hive的交互模式下命令:

quit / exit:退出CLI

reset:重置所有的配置参数,初始化为hive-site.xml中的配置。如之前使用set命令设置了reduce数量。

set <key>=<value>:设置Hive运行时配置参数,优先级最高,相同key,后面的设置会覆盖前面的设置。

set –v:打印出所有Hive的配置参数和Hadoop的配置参数。

//找出和"mapred.reduce.tasks"相关的设置
hive -e 'set -v;' | grep mapred.reduce.tasks

add命令:包括add File[S]/Jar[S]/Archive[S] <filepath> *,向 DistributeCache 中添加一个或过个文件、jar包、或者归档,添加之后,可以在Map和Reduce task中使用。比如,自定义一个udf函数,打成jar包,在创建函数之前,必须使用add jar命令,将该jar包添加,否则会报错找不到类。

list 命令:包括list File[S]/Jar[S]/Archive[S]。列出当前DistributeCache中的文件、jar包或者归档。

delete 命令:包括 delete File[S]/Jar[S]/Archive[S] <filepath>*。从DistributeCache中删除文件。

//将file加入缓冲区
add file /root/test/sql; //列出当前缓冲区内的文件
list file; //删除缓存区内的指定file
delete file /root/test/sql;

create命令:创建自定义函数:hive> create temporary function udfTest as ‘com.cstore.udfExample’;

source <filepath>:在CLI中执行脚本文件。

//相当于[root@ncst test]# hive -S -f /root/test/sql
hive> source /root/test/sql;

! <command>:在CLI执行Linux命令。

dfs <dfs command>:在CLI执行hdfs命令

4.保存查询结果の三种方式:

% hive -S -e 'select * from dummy' > a.txt //分隔符和hive数据文件的分隔符相同
[root@hadoop01 ~]# hive -S -e "insert overwrite local directory '/root/hive/a'\
> row format delimited fields terminated by '\t' --分隔符\t
> select * from logs sort by te" 
--使用hdfs命令导出整个表数据
hdfs dfs -get /hive/warehouse/hive01 /root/test/hive01 

5.Hive集群间的导入和导出

使用Export命令会导出Hive表的数据表数据以及数据表对应的元数据

--导出命令
EXPORT TABLE test TO '/hive/test_export' --dfs命令查看
hdfs dfs -ls /hive/test_export --结果显示
/hive/test_export/_metadata
/hive/test_export/data

使用Import命令将导出的数据重新导入到hive中(必须将现导入的表重命名)

--导入到内部表的命令
IMPORT TABLE data_managed FROM '/hive/test_export' --导入到外部表的命令
Import External Table data_external From '/hive/test_export' Location '/hive/external/data' --验证是否是外部表
desc formatted data_external

6.Hive - JDBC/ODBC

在Hive的jar包中,"org.apache.hadoop.hive.jdbc.HiveDriver"负责提供 JDBC 接口,客户端程序有了这个包,就可以把 Hive 当成一个数据库来使用,大部分的操作与对传统数据库的操作相同,Hive 允许支持 JDBC 协议的应用程序连接到 Hive。当 Hive 在指定端口启动 hiveserver 服务后,客户端通过 Java 的 Thrift 和 Hive 服务器进行通信。过程如下:

  1.开启 hiveserver 服务:$ hive –service hiveserver 50000(50000)

  2.建立与 Hive 的连接:Class.forName(“org.apache.hadoop.hive.jdbc.HiveDriver”);

     Connection con= DriverManager.getConnection(“jdbc:hive://ip:50000/default,”hive”,”hadoop”)

     默认只能连接到 default 数据库,通过上面的两行代码建立连接后,其他的操作与传统数据库无太大差别。

  3.Hive 的 JDBC 驱动目前还不太成熟,并不支持所有的 JDBC API。

7.Hive Web Interface

  1.配置hive-site.xml

        <property>
<name>hive.hwi.war.file</name>
<value>lib/hive-hwi-0.8.1.war</value>
<description>This sets the path to the HWI war file, relative to ${HIVE_HOME}.</description>
</property> <property>
<name>hive.hwi.listen.host</name>
<value>0.0.0.0</value>
<description>This is the host address the Hive Web Interface will listen on</description>
</property> <property>
<name>hive.hwi.listen.port</name>
<value>9999</value>
<description>This is the port the Hive Web Interface will listen on</description>
</property>

  2.启动Hive的Web服务:hive --service hwi

  3.在浏览器键入地址:http://host_name:9999/hwi访问

  4.点击“Create Session”创建会话,在Query中键入查询语句

8. Hive创建数据库

hive启动后默认有一个Default数据库,也可以人为的新建数据库,命令:

--手动指定存储位置
create database hive02 location '/hive/hive02'; --添加其他信息(创建时间及数据库备注)
create database hive03 comment 'it is my first database' with dbproperties('creator'='kafka','date'='2015-08-08');
--查看数据库的详细信息
describe database hive03;
--更详细的查看
describe database extended hive03;
--最优的查看数据库结构的命令
describe database formatted hive03;
--database只能修改dbproperties里面内容
alter database hive03 set dbproperties('edited-by'='hanmeimei');

Hive Shell常用操作的更多相关文章

  1. 【mongodb系统学习之八】mongodb shell常用操作

    八.mongodb  shell常用基础操作(每个语句后可以加分号,也可以不加,看情况定(有的工具中可以不加),最好是加): 1).进入shell操作界面:mongo,上边已有演示: 2).查看当前使 ...

  2. 二、hive shell常用命令

    在使用hive shell之前我们需要先安装hive,并启动hdfs 请参考:https://www.cnblogs.com/lay2017/p/9973298.html hive shell 我们先 ...

  3. Spark环境搭建(二)-----------HDFS shell 常用操作

    配置好HDFS,也学习了点HDFS的简单操作,跟Linux命令相似 1)  配置Hadoop的环境变量,类似Java的配置 在 ~/.bash_profile 中加入 export HADOOP_HO ...

  4. hive的常用操作

    1.hive的数据类型 tinyint/smallint/int/bigint tinyint:从 0 到 255 的整型数据 smallint:从 0 到 65535 的整型数据 int:从 0 到 ...

  5. Hive基础之Hive表常用操作

    本案例使用的数据均来源于Oracle自带的emp和dept表 创建表 语法: CREATE [EXTERNAL] TABLE [IF NOT EXISTS] [db_name.]table_name ...

  6. HIVE的常用操作(HQL)语句

    HIVE基本操作命令 创建数据库 >create database db_name; >create database if not exists db_name;//创建一个不存在的数据 ...

  7. HBase基础之Hbase shell常用操作

    一般操作 查看服务器状态 status 查看hbase版本 version DDL操作 创建表 create 'member','member_id','address','info' 创建了3个列族 ...

  8. Linux Bash shell常用操作快捷键

    转自:https://linuxtoy.org/archives/bash-shortcuts.html 生活在 Bash shell 中,熟记以下快捷键,将极大的提高你的命令行操作效率. 编辑命令 ...

  9. Shell常用操作

    1.读取配置文件中的jdbc_url参数的值($InputParamFile为待读取的目标文件绝对路径) jdbc_url=`grep "jdbc_url" $InputParam ...

随机推荐

  1. Ubuntu安装atom

    sudo add-apt-repository ppa:webupd8team/atom sudo apt-get update sudo apt-get install atom 安装的时如果报错, ...

  2. lightoj1132—Summing up Powers (取膜技巧&&组合数应用)

    题目链接:https://vjudge.net/problem/LightOJ-1132 题目意思:(1K + 2K + 3K + ... + NK) % 232 矩阵快速幂的题目一般都很短,这道题也 ...

  3. _init_() got an unexpected keyword argument ‘shape’

    按照<TensorFlow:实战Google深度学习框架>一书学习的tensorflow,书中使用的是0.9.0版本,而我安装的是1.11.0 如果按照书上的例子来,因为这本书使用tens ...

  4. 品友互动大数据平台的技术演化 https://www.sohu.com/a/191202836_99982360

    品友互动大数据平台的技术演化

  5. Network Security Services If you want to add support for SSL, S/MIME, or other Internet security standards to your application, you can use Network Security Services (NSS) to implement all your securi

    Network Security Services | MDN https://developer.mozilla.org/zh-CN/docs/NSS 网络安全服务 (NSS) 是一组旨在支持支持安 ...

  6. remote tomcat monitor---jmc--jvisualvm

    http://mspring.org/article/1229----------jmc http://doorgods.blog.163.com/blog/static/78547857201481 ...

  7. 拖拽js和jq写法

    第一种原生js写法 window.onload=function () { var oDrag=document.getElementById('drag'); oDrag.onmousedown=f ...

  8. git学习------>在CenterOS系统上安装GitLab并自定义域名访问GitLab管理页面

    目前就职的公司一直使用SVN作为版本管理,现在打算尝试从SVN迁移到Git.安排我来预言并搭建好相关的环境以及自己尝试使用Git.今天我就尝试在Center OS系统上安装GitLab,现在在此记录一 ...

  9. mysql 约束条件 auto_increment 自动增长

    约束字段为自动增长,被约束的字段必须同时被key约束 id自动增长,每插入一条记录,自动增长 创建一张表 t20 id 字段设置为 不为空 唯一 自动增长 mysql)); Query OK, row ...

  10. Spring boot 打包瘦身方法

    背景 随着spring boot 的流行.越来越多的来发着选择使用spring boot 来发 web 应用. 不同于传统的 web 应用 需要 war 包来发布应用. spring boot 应用可 ...