hive基础操作—(1)

时间:2023-03-09 04:23:44
hive基础操作—(1)

执行./hive命令后,进入CLI(shell)模式;

1、创建数据库,语句:

create database school;

2、展示所有的数据库,语句:

show databases;

3、选择使用的数据库,语句:

use school;

4、创建表语句(简单),语句:

create table student (id int, name String) row format delimited fields terminated by '\t';

后面的语句是指定列之间的分隔符。

5、向表中导入数据:

首先新建一个student.txt,并插入如下内容:

1       zhangsan
2 lisi
3 wangwu
4 zhaoliu

然后,执行:load data local inpath '/home/dyh/hive/student.txt' into table student;

6、查询表中的数据,语句:

select *from student;

7、统计表student中的数量,语句:

select count(*) from student;

执行改语句,就可以看到hive自动生成maprduce程序,进行map和reduce操作过程。

8、安装姓名排序,语句:

select *from student order by name desc;

select*from student order by name asc;