Hive的交互方式
第一种交互方式:bin/hive
cd/export/servers/hive-2.1.0/
bin/hive
创建一个数据库
create database mytest;
show databases;
第二种交互方式:使用sql语句或者sql脚本进行交互
不进入hive的客户端直接执行hive的hql语句
cd/export/servers/hive-2.1.0/
bin/hive -e "create database mytest"
或者我们可以将我们的hql语句写成一个sql脚本然后执行
cd/export/servers
vim hive.sql
脚本内容如下:
create database mytest2;
use mytest2;
create table stu(id int,name string);
通过hive -f 来执行我们的sql脚本
bin/hive -f /export/servers/hive.sql
第三种交互方式:Beeline Client
hive经过发展,推出了第二代客户端beeline,但是beeline客户端不是直接访问metastore服务的,而是需要单独启动hiveserver2服务。
在hive运行的服务器上,首先启动metastore服务,然后启动hiveserver2服务。
nohup /export/servers/hive-2.1.0/bin/hive --service metastore &
nohup /export/servers/hive-2.1.0/bin/hive --service hiveserver2 &
nohup 和 & 表示后台启动
在node3上使用beeline客户端进行连接访问。
/export/servers/hive-2.1.0/bin/beeline
根据体型进行一下操作;
[root@node3 ~]# /export/servers/hive-2.1.0/bin/beeline
which: no hbase in (:/export/servers/hive-2.1.0/bin::/export/servers/hadoop-2.7.5/bin:/export/servers/hadoop-2.7.5/sbin::/export/servers/jdk1.8.0_241/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/export/servers/mysql-5.7.29/bin:/root/bin)
Beeline version 2.1.0 by Apache Hive
beeline> !connect jdbc:hive2://node3:10000
Connecting to jdbc:hive2://node3:10000
Enter username for jdbc:hive2://node3:10000: root
Enter password for jdbc:hive2://node3:10000:123456
连接成功之后,出现以下内容,可以在提示符后边输入hive sql命令
注意: 如果报出以下, 请修改 hadoop中 core-site.xml文件
错误信息为: User: root is not allowed to impersonate root
解决方案: 在node1的 hadoop的 core-site.xml文件中添加一下内容:
<property>
<name>hadoop.proxyuser.root.hosts</name>
<value>*</value>
</property>
<property>
<name>hadoop.proxyuser.root.groups</name>
<value>*</value>
</property>
添加后, 将 core-site.xml 发送到其他两台机子:
cd /export/serverss/hadoop-2.7.5/etc/hadoop
scp core-site.xml node2:$PWD
scp core-site.xml node3:$PWD
然后重启hadoop即可