hive所在目录
/opt/apache-hive-2.3.5-bin/
在启动了haddop的情况下,在hive的安装目录下输入bin/hive,启动hive
[root@hadoop01 ~]# cd /opt/apache-hive-2.3.5-bin/
[root@hadoop01 apache-hive-2.3.5-bin]# bin/hive
查看数据库
hive> show databases;
创建数据库muc
hive> create database muc;
使用数据库muc
hive> use muc;
创建数据表student,有int类型的id和string类型的name
hive> create table student(id int,name string)
> row format delimited
> fields terminated by '\t'
> stored as textfile;
退出hive
hive> quit;
在hdfs下创建目录 /user/hive/warehouse,-p代表子目录与父目录同时创建
[root@hadoop01 apache-hive-2.3.5-bin]# hadoop fs -mkdir -p /user/hive/warehouse
给文件组成员赋予该目录读和写的权限
[root@hadoop01 apache-hive-2.3.5-bin]# hadoop fs -chmod g+w /user/hive/warehouse
在根目录下新建一个person1.txt,里面写id 和name,中间用tab键隔开
创建文件
[root@hadoop01 apache-hive-2.3.5-bin]# cd
[root@hadoop01 ~]# vi person1.txt
文件内容
1 zhangsan
2 lisi
将该文件上传到hdfs的/user/hive/warehouse/muc.db/student目录中(在hive中创建数据库和数据表即在hdfs上创建文件目录)
[root@hadoop01 ~]# hadoop fs -put /root/person1.txt /user/hive/warehouse/muc.db/student
再次启动hive
[root@hadoop01 ~]# cd /opt/apache-hive-2.3.5-bin/
[root@hadoop01 apache-hive-2.3.5-bin]# bin/hive
使用数据库muc
hive> use muc;
查看student表的内容
hive> select * from student;
删除表student
hive> DROP TABLE IF EXISTS student;
删除数据库muc
hive> DROP DATABASE IF EXISTS muc;
此时再查看hive中的数据库,发现数据库muc已被删除
hive> show databases;