当前位置:   article > 正文

命令行操作Hive_进入hive命令模式的命令是

进入hive命令模式的命令是

针对命令行这种方式,其实还有两种使用
第一个是使用bin目录下的hive命令,这个是从hive一开始就支持的使用方式。后来又出现一个beeline命令,它是通过HiveServer2服务连接hive,它是一个轻量级的客户端工具,所以 后来官方开始推荐使用这个。

1:先看第一种,这种直接就可以连进去

[root@test apache-hive-3.1.2-bin]# bin/hive
Hive-on-MR is deprecated in Hive 2 and may not be available in the future ver
Hive Session ID = e106db23-21b8-488f-8c13-85efd30f395a
hive>
  • 1
  • 2
  • 3
  • 4

这里有一行信息提示,从Hive2开始Hive-on-MR就过时了,并且在以后的版本中可能就不维护了,建议 使用其它的计算引擎,例如:spark或者tez

下面以hive开头的内容就是说明我们进入了Hive的命令行中,在这里就可以写Hive的SQL了

创建一个表

hive> create table t1(id int,name string);
OK
Time taken: 1.064 seconds
  • 1
  • 2
  • 3

查看有哪些表

hive> show tables;
OK
t1
Time taken: 0.18 seconds
  • 1
  • 2
  • 3
  • 4

向表里面添加数据

hive> insert into t1(id,name) values(1,"zs");
Query ID = root_20200506162317_02b2802a-5640-4656-88e6-1e4eaa811017
Total jobs = 3
Launching Job 1 out of 3
Number of reduce tasks determined at compile time: 1
In order to change the average load for a reducer (in bytes):
  set hive.exec.reducers.bytes.per.reducer=<number>
In order to limit the maximum number of reducers:
  set hive.exec.reducers.max=<number>
In order to set a constant number of reducers:
set mapreduce.job.reduces=<number>
Starting Job = job_1588737504319_0001, Tracking URL = http://bigdata01:8088/
Kill Command = /data/soft/hadoop-3.2.0/bin/mapred job -kill job_15887375043 Hadoop job information for Stage-1: number of mappers: 1; number of reducers 2020-05-06 16:23:36,954 Stage-1 map = 0%, reduce = 0%
2020-05-06 16:23:47,357 Stage-1 map = 100%, reduce = 0%, Cumulative CPU 3.1 2020-05-06 16:23:56,917 Stage-1 map = 100%, reduce = 100%, Cumulative CPU 5 MapReduce Total cumulative CPU time: 5 seconds 160 msec
Ended Job = job_1588737504319_0001
Stage-4 is selected by condition resolver.
Stage-3 is filtered out by condition resolver.
Stage-5 is filtered out by condition resolver.
Moving data to directory hdfs://bigdata01:9000/user/hive/warehouse/t1/.hive- Loading data to table default.t1
MapReduce Jobs Launched:  Stage-Stage-1: Map: 1 Reduce: 1 Cumulative CPU: 5.16 sec HDFS Read: 1520 Total MapReduce CPU Time Spent: 5 seconds 160 msec
OK
Time taken: 41.534 seconds
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

可以看到,此时就产生了MapReduce任务

查询数据

hive> select * from t1;
OK
1       zs
Time taken: 2.438 seconds, Fetched: 1 row(s)
  • 1
  • 2
  • 3
  • 4

删除表

hive> drop table t1;
OK
Time taken: 0.89 seconds
  • 1
  • 2
  • 3

2:接着看一下第二种方式 beeline
我们要先启动hive的服务

bin/hiveserver2
  • 1

然后使用beeline连接

bin/beeline -u jdbc:hive2://localhost:10000
  • 1

这里可能会碰到匿名用户对/tmp/hadoop-yarn没有权限的问题,解决方案有两个:

  1. 给hdfs中的/tmp/hadoop-yarn设置777权限,让匿名用户具备权限可以直接给tmp及下面的所有目录设置777权限
hdfs dfs -chmod -R 777 /tmp
  • 1
  1. 在启动beeline的时候指定一个对这个目录有操作权限的用户
bin/beeline -u jdbc:hive2://localhost:10000 -n root
  • 1

具体的表操作和方式1是一样的,这里就不重复讲解了。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小惠珠哦/article/detail/745377
推荐阅读
相关标签
  

闽ICP备14008679号