hive操作常见的一些命令

1.关于库/表操作

  • 建库 create database mydb; create database if no exists mydb; create database if no exists mydb location “/aa/bb”;

  • 查询数据库 查询库列表:show databases; 查询库详细信息:desc database [extended] mydb; 查询建库的详细信息:show create database mydb;

  • 删除数据库 drop database mydb; drop database if exists mydb; drop database if exists mydb [restrict|cascade];

  • 先进入我们要操作的数据库/切换库 use mydb;

  • 查看数据库里面的表 show tables; show tables in mydb;

  • 添加表 创建内部表(Managered_Table) create table mingxing_mng(id int, name string, sex string, age int, department string) row format delimited fields terminated by ‘,’;

  • 删除表 drop table mingxing; drop table if exists mingxing;

  • 对表进行重命名 alter table mingxing rename to student;

  • 对表的字段进行操作(增加add,删除drop,修改change,替换replace) 增加字段: alter table mingxing add columns (province string); alter table mingxing add columns (province string, salary bigint);

  • 增加分区: alter table mingxing_ptn add partition(city=‘beijing’); alter table mingxing_ptn add partition(city=‘beijing’) partition(city=‘tianjin’);

  • 删除分区: alter table mingxing_ptn drop partition(city='beijing'); alter table mingxing_ptn drop partition(city='beijing'), partition(city='tianjin');

  • 修改分区路径: alter table mingxing_ptn partition(city="beijing") set location "/mingxing_beijing";

  • 查看库:show databases; 查看表:show tables; 查看建表完整语法:show create table mingxing_mng; 查看内置函数库:show functions; 查看函数的详细手册:desc function extended concat; 查看分区:show partitions mingxing_ptn; 查看表的字段:desc mingxing_mng; 查看表的详细信息:desc extended mingxing_mng; 查看表的格式化了之后的详细信息:desc formatted mingxing_mng;

  • like关键字使用:复制表结构 create table student like mingxing;

  • 清空数据库表中的数据 truncate table mingxing2;

2.数据操作

  • 单条数据插入: insert into table mingxing values(001,‘huangbo’,‘male’,50,‘MA’);

  • 单重插入模式: insert ... select .... insert into table student select id,name,sex,age,department from mingxing; 注意:查询出的字段必须是student表中存在的字段

  • 多重插入模式: from mingxing insert into table student1 select id,name,sex,age insert into table student2 select id,department; from mingxing2 insert into table student1 partition(department='MA') select id,name,sex ,age where department='MA' insert into table student1 partition(department='CS') select id,name,sex ,age where department='CS';

  •  

posted @ 2020-01-02 15:32  数据阮小白  阅读(160)  评论(0编辑  收藏  举报