温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

hive的指令操作及内外临时表的创建

发布时间:2020-06-03 16:24:41 来源:网络 阅读:12317 作者:厦小岗 栏目:数据库


2、数据库: OLTP //online transaction process ,在线事务处理


3、drop databases  if exists  mybase //删除数据库


4、show tables //显示表


5、create  database  mybase //mysql 创建库


6、create table test(id int ,name varchar(20)); //创建列表


7、select id from test        //查看表中的内容


8、两张表合成:select a.*,b.* form tbls a,columms_v2 b where a.tbl_id = b.tbl_id 


9、show databases; //显示数据库


10、在/soft/hive/bin/下执行:hive 后再执行:create database if not exists mybase;


11、用自己的库的话就执行:use mybase ;   ------>记得加分号

show tables; ——————》显示表信息


12、创建表:create table test(id int , name varchar(20));


13、查看表的结构:desc test


14、往数据库里面放数据:insert into test(id,name)values(1,'tom');


15、select * form test      //查看表中所有的内容




具体流程是:创建库:create database mysbase ------>用那个库use mybase  ------->创建表create table test(id int ,name varchar(20))




-----------------------------------------------------


表的填写信息及创建语法:

1、create  table if not exists employee(edi int ,nam String,salary String, destination String)


2、comment ‘employee details’



4、 row format delimited  fields terminated by ‘\t’ //这行的格式分隔如何 :(1  tom  12 )


5、lines terminated by ‘\n’ //换行1  tom  12

     2  tod  13


6、stored as textfile;   //存储为文本文件



dfs -lsr / ; //查看它们的目录结构


-------------------------------------------------------------------------------------------

desc[ribe] database mybase ; //查看数据库信息

alter database mybase set dbproperties ('created'='xpc'); //修改数据库,增加数据库属性

desc database extended mybase ; //显示数据库扩展信息,不能格式化输出

desc extended default.test0 ; //显示表扩展信息

desc formatted default.test0 ; //显示表格式化信息

desc extended test ; //显示表的扩展信息

create database mybase location '/x/x/x/x' //指定数据库存放hdfs位置

create table default.test0 like mybase.test2 ; //复制表结构


load data local ... //上传本地文件到hdfs

load data '/x/x/x' into table xx //移动hdfs文件系统上的数据文件。

insert into mybase.test2 select * from default.test0 where id > 1204 ; //复制表数据


create table mybase.test3 as select * from default.test0 ; //复制表(表结构 + 数据)

select all id,name from test2 ; //查询所有记录(不去重)

select distinct id,name from test2 ; //查询所有记录(去重)


--------------------------------------------------------

拷贝一张已经存在的表模式

create table if ont exists mydb.employees2 like mydb.employees


-------------------------------------------


如何从本地插进文本文件:

load data local inpath '/home/user/sample.txt' overwrite into table tset;

----------------------------------------------------------

外部表的创建步骤:

1、create database mybase ;  //创建库

2、use  mybase  ;          //用库

3、create external table etest(id int ,name string,age int) row format delimited fields terminated by '\t' stored as textfile ;//创建外部表


4、查看表的参数: desc formatted etest ; 查看有 多少张表:show tables  看表的结构select * from etest ;


5、创建临时表create tempporary table temp(id int ,name string,age int) row format delimited fields terminated by '\t' stored as textfile ;


6、CTAS:create table as select 


7、truncate  :删除所有的行,只能用于内部的表


8、修改表分隔符:alter table table_name set serdeproperties (‘field,delimi’= ',')


9、修改表的位置:alter table 表名 set location 'hdfs:/xxx/x/表名'



分区表

------------

[手动分区--静态分区]

1.预先定义分区列和存储数据到表的子目录下。

2.创建分区表

create table xxx(...) partitioned by (year int ,month int) row format ...;


3.给分区表添加多个分区(手动分区)

alter table partest add partition (year=2016,month=4) partition (year=2016,month=5);

4.显示指定表的分区

show partitions partest ;

5.删除分区

ALTER TABLE partest DROP IF EXISTS PARTITION (year=2014, month=11);

6.加载数据到指定的分区目录下。

LOAD DATA LOCAL INPATH '..sample.txt' OVERWRITE INTO TABLE partest PARTITION (year=2016, month=4);

单是查询2016年4月份的数据:select * from  表名 where year=2016 and month = 4 ;


7.启动动态分区(默认是开启的)

SET hive.exec.dynamic.partition=true; //启动动态分区.

//默认是strict,是严格模式,至少要指定一个分区类,通过如下指令关闭严格模式。

SET hive.exec.dynamic.partition.mode=nonstrict; //设置分区模式,非严格.

8.测试动态分区

insert into table partest partition(year,month) select id,name,age,year,month from test ;



























向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI