hive的基本操作

进入某个库:use  bigdata;   bigdata为库名;

显示所有的表:show tables;

显示正则匹配的表:show tables ‘.table*';    .为任意一个字符,*为多个字符

删除表: drop table tablename;  tablename为表名称

创建普通表:create table tablename(id string,name string);

创建分区表:create table tablename(id string,name string) partitioned by (day_id string);

重命名表:alter table tablename rename to tablenametest;

增加列:alter table tablename add columns(cc string comment '增加的新列');

查看表结构: desc tablename;    show create table tablename;

查看分区信息: show partitions tablename;

将文件导入到hive表中:load data local inpath '/home/hadoop/input/haha.txt' overwrite into table tablename partition (day_id='20160508');

加local,用本地文件,不加local,用hdfs上文件;

不加overwrite,追加数据,加overwrite,重写表数据;

对于本地文件,直接传到HIVE的HDFS上,但是,对于HDFS上的文件要导入,会将HDFS上的文件移动到HIVE对应的HDFS目录中。

如果有重名的,不加OVERWRITE ,会将HDFS上的文件重命名,并报错,数据导入也会失败

将查询结果插入到tablename中:insert overwrite table tablename select * from table_test;

加overwrite会重写tablename表数据

将查询结果插入到文件中:insert overwrite local directory '/home/hadoop/out' select * from student;

加overwrite会重写文件,否则会追加;加local会写到本地,否则会写的HDFS中


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值