hive数据库的常用命令操作

启动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)>
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值