六、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;
相关推荐
nvd1120 小时前
折腾 Niri WM:手搓一个完美的多显示器下拉终端 (Drop-down Terminal)
数据仓库
QQ129584550420 小时前
FERP50 - Excel以存储过程方式访问数据仓库
数据仓库·spark·excel
It's Q20 小时前
Hive序列函数&&排名函数
数据仓库·hive·hadoop
Irene199120 小时前
外部表(EXTERNAL_TABLE)Hive 借用数据,删表不删数据
hive·内部表·外部表
WL_Aurora2 天前
Hadoop HA高可用架构深度解析
大数据·hadoop·架构
Irene19912 天前
Windows 11 WSL Ubuntu 环境:实际安装 Hive 踩坑实录
hive·windows·ubuntu
Irene19912 天前
Windows 11 WSL Ubuntu 环境:实际安装 Hadoop 踩坑实录
linux·hadoop·ubuntu
Irene19912 天前
(课堂笔记)Hive 分区、分桶与数据倾斜
hive·hadoop
Irene19913 天前
在 WSL Ubuntu 上安装和使用 Hive
linux·hive·ubuntu
二宝哥3 天前
大数据之安装Hadoop3.1.4
大数据·hadoop