进入某个库: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中