学习hive

1、进入hive数据库:hive

2、查看hive中的所有数据库:show databases;

3、用default数据库:use default;

4、查看所有的表:show tables;

5、查询表结构:desc mytest(表名);

6、查询表数据: select * from mytest(表名);

7、创建数据库:hive> CREATE SCHEMA userdb;

8、验证数据库表:hive> SHOW DATABASES;

9、删除数据库:hive> DROP DATABASE IF EXISTS userdb;

                          hive> DROP SCHEMA userdb;

     全部删除相应的表在删除数据库之前:hive> DROP DATABASE IF EXISTS userdb CASCADE;

10、创建表employee

   hive> create table if not exists employee (eid int,name String,salary String,destination String)

    > comment 'employee details'

    > ROW FORMAT DELIMITED

    > FIELDS TERMINATED BY '\t'

    > LINES TERMINATED BY '\n'

   > STORED AS TEXTFILE;

如果增加分区必须在创建表的时候就创建分区,不然就会报错,创建分区的命令>partition by ‘根据哪个字段分区’,

 hive> create table employee (id int, name String, dept String)

    > PARTITIONED BY (year int)

    > ROW FORMAT delimited

    > fields terminated by '\t'

    > lines terminated by '\n'

    > stored as textfile;

stored as textfile文件格式,文件格式在hive中有三种: textfile、Sequencefile(序列化文件,学hadoop的都会知道啦)、Rcfile。

posted @ 2021-09-24 18:14  yasai  阅读(88)  评论(0)    收藏  举报