随笔 - 118  文章 - 0 评论 - 0 阅读 - 2904
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

我本周观看了黑马程序员的hadoop入门课程的相关hive数据库的操作命令

启动hive

hive
1
启动成功就进入了hive的shell操作界面。

查看数据库
hive> show databases;
OK
default
hive1
hive2
Time taken: 0.031 seconds, Fetched: 3 row(s)
1
2
3
4
5
6
查看表
hive> show tables;
OK
helloworld
Time taken: 0.056 seconds, Fetched: 1 row(s)
1
2
3
4
切换数据库
hive> use hive1;
OK
Time taken: 0.013 seconds
1
2
3
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
1
2
3
4
5
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)
显示表所在的数据库
当前会话有效:

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)>

posted on   满山猩猩我脸最黑  阅读(5)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Ollama——大语言模型本地部署的极速利器
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· Windows编程----内核对象竟然如此简单?
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
历史上的今天:
2022-08-10 20213901 田铭庚 2022.8.7-2022.8.13 总结
2022-08-10 20213901 田铭庚 信2105-3 2022.7.31-2022.8.6 总结
点击右上角即可分享
微信分享提示