第一种交互方式bin/hive
首先运行bin目录下的hive脚本启动hive
cd /export/servers/apache-hive-2.1.1-bin/
bin/hive
创建一个数据库
create database if not exists mytest;
第二种交互方式:使用sql语句或者sql脚本进行交互
不进入hive的客户端直接执行hive的hql语句
cd /export/servers/apache-hive-2.1.1-bin
bin/hive -e "create database if not exists mytest;"
或者我们可以将我们的hql语句写成一个sql脚本然后执行
cd /export/servers
vim hive.sql
//创建数据库
create database if not exists mytest;
//使用数据库
use mytest;
//创建表
create table stu(id int,name string);
通过hive -f 来执行我们的sql脚本
bin/hive -f /export/servers/hive.sql
第三种交互方式:把Hive进程挂载到后台或者前台(推荐)
把服务挂载到前台
bin/hive --service hivesever2
把服务挂载到后台之中
nohup bin/hive --service hivesever2 2>&1 &
连接到服务端
hive目录下执行
/bin/beeline
#等出现beeline>输入
!connect jdbc:hive2://node01:10000
#然后输入用户名,密码(随意)
Enter username for jdbc:hive2://node01:10000: root
Enter password for jdbc:hive2://node01:10000: ********
如果控制台显示
0: jdbc:hive2://hadoop01:10000>
说明客户端连接成功。
ps:如果遇到User: root is not allowed to impersonate anonymous (state=08S01,code=0)
问题,说明HDFS权限不足。我们在/hadoop/etc/hadoop/core-site.xml
中添加一段
<property>
<name>hadoop.proxyuser.root.groups</name>
<value>root</value>
<description>Allow the superuser oozie to impersonate any members of the group group1 and group2 </description>
</property>
<property>
<name>hadoop.proxyuser.root.hosts</name>
<value>*</value>
<description>The superuser can connect only from host1 and host2 to impersonate a user </description>
</property>
然后重启整个HDFS即可解决。
网友评论