文章目录
2.Hive安装
2.1Hive安装
2.2HiveJDBC访问
2.2.1启动hiveserver2服务
hiveserver2
2.2.2连接hiveserver2服务
新建命令窗口
,输入以下命令
beeline -u "jdbc:hive2://localhost:10000"
出现该图代表成功连接
2.2.3注意
这里报错通常是由于权限不够,只需要对tmp和opt文件夹赋权即可
hadoop fs -chmod -R 777 /tmp
hadoop fs -chmod -R 777 /opt
2.3Hive常用交互命令
1.“-e”不进入hive的交互窗口执行sql语句
hive -e "查询语句"
2.“-f”执行脚本中sql语句
hive -f sql文件路径/sql文件名称
执行文件中的sql语句并将结果写入文件中
hive -f sql文件路径/sql文件名称 > 保存结果的路径
2.4Hive其他命令操作
1.退出hive窗口
exit;
quit;
2.在hive cli命令窗口中如何查看hdfs文件系统
dfs -ls /;
3.在hive cli命令窗口中如何查看本地文件系统
!ls /opt;
2.5Hive常见属性配置
2.5.1数据仓库位置配置
修改hive-site.xml文件的value
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/opt/hive/warehouse</value>
</property>
2.5.2查询后信息显示配置
在hive-site.xml
文件中添加如下配置信息,就可以实现显示当前数据库,以及查询表的头信息配置。
<property>
<name>hive.cli.print.header</name>
<value>true</value>
</property>
<property>
<name>hive.cli.print.current.db</name>
<value>true</value>
</property>
重新启动hive,对比配置前后差异。
2.5.3运行日志信息配置
- Hive的log默认存放在
/tmp/root/hive.log
目录下(root为当前用户名)
- 修改hive的log存放日志到
/opt/hive/logs
1.修改/opt/hive/conf/hive-log4j.properties.template
文件名称为hive-log4j.properties
mv hive-log4j.properties.template hive-log4j.properties
2.在hive-log4j.properties
文件中修改log
存放位置
hive.log.dir=/opt/hive/logs
重启hive