启动hive
hive
启动成功就进入了hive的shell操作界面。
查看数据库
hive> show databases;
OK
default
hive1
hive2
Time taken: 0.031 seconds, Fetched: 3 row(s)
查看表
hive> show tables;
OK
helloworld
Time taken: 0.056 seconds, Fetched: 1 row(s)
切换数据库
hive> use hive1;
OK
Time taken: 0.013 seconds
1.创建库,添加备注,添加数据库属性
hive> create database if not exists hive2
> comment "this is a test database"
> with dbproperties('creator'='test','date'='2020-08-27');
OK
Time taken: 0.036 seconds
2.创建表,定义2个字段
hive> create table helloworld(id int,name string);
OK
Time taken: 0.381 seconds
3.查看表结构
hive> desc helloworld;
OK
id int
name string
Time taken: 0.27 seconds, Fetched: 2 row(s)
4.创建表,使用空格分隔
hive> create table hello(in int,name string)
> row format delimited fields terminated by '\t';
OK
Time taken: 0.309 seconds
5.导入本地数据到hive的表,覆盖表内容
(本质就是将本地文件上传到hive数据库)
overwrite表示覆盖相同的数据,不写overwrite会添加相同的数据。
hive> load data local inpath '/home/hadoop/app/tmp/data/hello.txt'
> overwrite into table hello;
Loading data to table hive2.hello
[Warning] could not update stats.
OK
Time taken: 23.727 seconds
6.查看表
hive> select * from hello;
OK
1 aa
2 bb
3 cc
Time taken: 0.045 seconds, Fetched: 3 row(s)
7.显示表所在的数据库
当前会话有效:
set hive.cli.print.current.db=true;
全局配置有效
在hive-site.xml中增加如下配置:
<property>
<name>hive.cli.print.current.db</name>
<value>true</value>
</property>
重启hive查看默认数据库的提示信息,成功:
hive (default)> use hive2; OK
Time taken: 1.144 seconds
hive (hive2)>