Hive个人心得笔记之基础指令
Hive个人心得笔记之基础指令
一.基础指令
desc 表 查看表结构
没有主键,可以重复提交
手动提交 效率过低,可以通过文件形式传输
load data local inpath ‘/home/software/1.txt’ into table stu; | 通过加载文件数据到指定的表里 |
但是,如果不指定分割格式,无法正常传输
命令 | 作用 | 额外说明 |
show databases; | 查看都有哪些数据库 |
|
create database park; | 创建park数据库 | 创建的数据库,实际是在Hadoop的HDFS文件系统里创建一个目录节点,统一存在: /user/hive/warehouse 目录下 |
use park; | 进入park数据库 |
|
show tables; | 查看当前数据库下所有表 |
|
create table stu (id int,name string); | 创建stu表,以及相关的两个字段 |
|
insert into stu values(1,’zhang’) | 向stu表插入数据 |
|
select from stu | 查看表数据 | 也可以根据字段来查询,比如select id from stu |
drop table stu | 删除表 |
|
select from stu | 查询stu表数据 |
|
load data local inpath ‘/home/software/1.txt’ into table stu; | 通过加载文件数据到指定的表里 |
|
create table stu1(id int,name string) row format delimited fields terminated by ‘ ‘;
| 创建stu1表,并指定分割符 空格。 |
|
desc stu | 查看 stu表结构 |
|
create table stu2 like stu | 创建一张stu2表,表结构和stu表结构相同 | like只复制表结构,不复制数据 |
insert overwrite table stu2 select from stu | 把stu表数据插入到stu2表中 |
|
insert overwrite local directory ‘/home/stu’ row format delimited fields terminated by ‘ ‘ select from stu; | 将stu表中查询的数据写到本地的/home/stu目录下 |
|
insert overwrite directory ‘/stu’ row format delimited fields terminated by ‘ ‘ select from stu; | 将stu表中查询的数据写到HDFS的stu目录下 |
|
from stu insert overwrite table stu1 select insert overwrite table stu2 select *; | 将stu表中查询的数据写到stu1以及stu2两张表中 |
|
alter table stu rename to stu2 | 为表stu重命名为stu2 |
|
alter table stu add columns (age int); | 为表stu增加一个列字段age,类型为int |
|
exit | 退出hive |
|
还没有评论,来说两句吧...