六、Hive的基本使用

文章目录

一、启动Hive

1、启动hive

复制代码
1.启动HDFS
start-dfs.sh
2.启动yarn
start-yarn.sh
3.开启历史服务器
mapred --daemon start historyserver
4.进入目录
cd /export/server/hive
5.后台启动
nohup bin/hive --service metastore >> logs/metastore.log 2>&1 &
6.启动 (前提是后台启动了nohup bin/hive --service metastore >> logs/metastore.log 2>&1 &)
bin/hive

2.基本操作

复制代码
1.创建表
create table students (id int,name string);
2.查看表
show tables;
3.插入数据
insert into students values(1,'张三'),(2,'李四');
4.查看表数据
select * from students;
5.按照学生的id进行分组,然后统计每个id出现的次数。
select id,COUNT(*) AS CNT from students group by id;

3.查看Hadoop数据的存放位置

复制代码
1.查看hadoop服务器下的根目录
hadoop fs -ls/
2.查看students文件夹下的所有内容
hadoop fs -cat /user/hive/warehouse/students/*

4.查看Mysql中元数据存放的位置

复制代码
1.登录数据库
mysql -u root -p
2.使用数hive据库
use hive;
3.查看表格
show tables;
4.查看数据
 select * from TBLS;

二、beeline的使用

1.HiveServer2服务

复制代码
中转站
HiveServer2可以对外提供一个端口10000,利用HiveServer2去连接其他的可视化操作工具,例如Navicat

2.启动HiveServer2服务

复制代码
cd /export/server/hive文件夹中去启动
1.先启动metastore服务
nohup bin/hive --service metastore >> logs/metastore.log 2>&1 &
2.然后启动HiveSever2
nohup bin/hive --service hiveserver2 >> logs/hiveserver2.log 2>&1 &
3.查看生成的日志文件
tail -f logs/hiveserver2.log

3.启动beeline服务

复制代码
cd /export/server/hive文件夹中去启动
1.启动beeline
bin/beeline
2.连接HiveServer2
!connect jdbc:hive2://hadoop01:10000
    用户名hadoop
    密码不输入直接回车
3.连接失败的话重启hdfs集群
停止 ''
stop-dfs.sh
stop-yarn.sh
开启
start-dfs.sh
4.查看效果
show databases;
相关推荐
忧郁火龙果3 小时前
五、安装配置hive
数据仓库·hive·hadoop
chad__chang17 小时前
dolphinscheduler安装过程
hive·hadoop
莫叫石榴姐1 天前
字节数开一面
大数据·数据仓库·职场和发展
ajax_beijing1 天前
hadoop的三副本数据冗余策略
大数据·hadoop·分布式
weixin_307779132 天前
在 Microsoft Azure 上部署 ClickHouse 数据仓库:托管服务与自行部署的全面指南
开发语言·数据库·数据仓库·云计算·azure
weixin_307779132 天前
AWS Redshift 数据仓库完整配置与自动化管理指南
开发语言·数据仓库·python·云计算·aws
yumgpkpm2 天前
CMP (类ClouderaCDP7.3(404次编译) )华为鲲鹏Aarch64(ARM)信创环境多个mysql数据库汇聚的操作指南
大数据·hive·hadoop·zookeeper·big data·cloudera
华阙之梦2 天前
【在 Windows 上运行 Apache Hadoop 或 Spark/GeoTrellis 涉及 HDFS 】
hadoop·windows·apache