1、 创建库:create database if not exists mydb;
2、 查看库:show databases;
3、 切换数据库:use mydb;
4、 创建表:create table if not exists t_user(id string, name string) 或 create table t_user(id string, name string) row format delimited fields terminated by ',';
5、 查看表列表:show tables;
6、 插入数据:insert into table t_user values ('1','huangbo'), ('2','xuzheng'), ('3','wangbaoqiang');
7、 查询数据:select * from t_user;
8、 导入数据:
a) 导入 HDFS 数据:load data inpath '/user.txt' into table t_user;
b) 导入本地数据:load data local inpath '/home/hadoop/user.txt' into table t_user;
user.txt 的数据为:
4,liudehua
5,wuyanzu
6,liangchaowei
9、再次查询数据:select * from t_user;
小技能补充:
1、 进入到用户的主目录,使用命令 cat /home/hadoop/.hivehistory 可以查看到 hive 执行的 历史命令
2、 执行查询时若想显示表头信息时,请执行命令: Hive> set hive.cli.print.header=true;
3、 hive的执行日志的存储目录在${java.io.tmpdir}/${user.name}/hive.log中,假如使用hadoop 用户操作的 hive,那么日志文件的存储路径为:/temp/hadoop/hive.log
本文详细介绍Hive SQL的基本操作,包括数据库与表的创建、数据的导入与查询等核心功能,适合初学者快速上手。
1902

被折叠的 条评论
为什么被折叠?



