hive常用命令,
hive的语法与MySQL、Oracle的语法类似,所以可以将MySQL、Oracle的语法在hive中使用,自己要勇于尝试。
查看hive中的数据库
show databases;
查看数据库信息
describe database '数据库名'
创建数据库
create database '数据库名';
查看hive数据库中的数据表
show tables;
创建数据表
create table '表名';
查看表信息
desc formatted '表名'
表重命名
alter table '表名' rename to '新表名'
删除数据库
drop database '数据库名'
删除数据表
drop table '数据表名'
添加列
alter table '表名' add|replace columns('字段' '数据类型')
注:add是表示新增一个字段,新增字段位置在所有已经存在字段之后,分区的虚拟字段之前,replace表示替换表中所有的字段(这个几乎不使用)
修改列
原始表结构[student(a string,b int,c int)]
alter table '表名'(student) change a a1 int
注:修改字段名
alter table '表名'(student) change a a1 string after b
注:修改字段名和对应的数据类型,并且改变字段的顺序(将字段a1置于字段b之后)
alter table '表名'(student) change c c1 string first
注:修改字段名和对数据类型,并且将改变字段的顺序(将字段c1放在首位)
清除数据表中的数据
turncate table '数据表名'
注:此操作只会清除数据表中的所有数据,不会删除表结构。
创建(内部)数据表
create table t1(id int ,name String) row format delimited fields terminated by ','
创建(外部)数据表
create external table t2 (id int,name String) row format delimited fields terminated by ','
外部表与内部表的区别
在hive中使用’external’关键字来创建外部表;所以在创建数据表时,只要没有使用关键字"external"创建的数据表都是内部数据表;反之,即为外部表。
在删除内部数据表时,会连同HDFS中存储的数据文本一起删除,而删除外部数据表时,只是在数据库中删除了该数据表的映射(元数据),HDFS存储的数据文本不会被删除,一旦再创建该数据表时,不用导入数据,该表中原先的数据仍然存在。
创建分区表
create table book (id bigint, name string) partitioned by (pubid int) row format delimited fields terminated by ','
删除分区表
alter table '数据表名' drop if exists partition('字段' = '具体数据')
注:'if exists’是判断语句,表示,如果存在这个分区,就将这个分区表删除;'字段’表示在创建分区表时,使用的那个分区字段。
修改分区
alter table 表名 partition('字段' = '具体数据') rename to partition('字段' = '具体数据')
显示分区表的信息
show partitions '分区表名'
注:此命令只适用分区表。
显示hive中的函数
show functions
创建分桶表
create table book (id bigint, name string) clustered by (id) into 4 backets row format delimited fields terminated by ','
本站文章为和通数据库网友分享或者投稿,欢迎任何形式的转载,但请务必注明出处.
同时文章内容如有侵犯了您的权益,请联系QQ:970679559,我们会在尽快处理。