Hive 1.1.3 - 常用sql操作
2019-10-25 本文已影响0人
No_七
1、查看数据库
hive (db01)> show databases;
2、使用数据库
hive (db01)> use db01;
3、查看所有的表
hive (db01)> show tables;
4、删除非空数据库
hive (db01)> drop database db01 cascade;
5、建表
5.1 建一个新表,并且以’\t’为间隔
hive (db01)> create table if not exists student01(
> num int,
> name string
> )
> row format delimited fields terminated by '\t';
5.2 创建一个新表student04,并且把 student03中的num,name字段插入进去
hive (db01)> create table student04 as select num,name from student03;
5.3 从student03复制表的结构到student05(数据不复制)
hive (db01)> create table student05 like student03;
6、查看表信息
hive (db01)> desc student;
hive (db01)> desc formatted student03;
7、加载数据到表中
7.1 复制本地文件 '/opt/datas/student.txt’ 到student03
hive (db01)>load data local inpath '/opt/datas/student.txt' into table student03;
7.2 移动hdfs上的文件 '/student.txt’ 到 student02
hive (db01)> load data inpath '/student.txt' into table student02;
8、删除表
hive (db01)> drop table if exists student02;
hive (db01)> drop table student05;
9、清除表的数据,保留结构
hive (db01)> truncate table student03;
10、修改表名
hive (db01)> alter table student01 rename to s01;
image.png
11、表添加字段
hive (db01)> alter table s01 add columns (age int);
image.png
12、修改字段类型 (修改age字段为point并且类型改为string)
hive (db01)> alter table s01 change age point string;
image.png