栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

2021.11.9单机版安装使用Hive

2021.11.9单机版安装使用Hive

1、解压hive压缩包
tar -zxf ./hive-1.1.0-cdh5.14.2.tar.gz -C /opt/soft/
2、修改减压后的文件名
mv hive-1.1.0-cdh5.14.2/ hive110
3、在hive110/conf下创建hive-site.xml文件
touch hive-site.xml
[root@gree139 conf]# vi ./hive-site.xml



  
    javax.jdo.option.ConnectionURL
    jdbc:mysql://192.168.153.139:3306/hive139?createDatabaseIfNotExist=true
  
  
    javax.jdo.option.ConnectionDriverName
    com.mysql.jdbc.Driver
  
  
    javax.jdo.option.ConnectionUserName
    root
  
  
    javax.jdo.option.ConnectionPassword
    root
  
  
    hive.server2.thrift.client.user
    root
  
  
    hive.server2.thrift.client.password
    root
  

配置hive环境
#hive
export HIVE_HOME=/opt/soft/hive110
export PATH=$PATH:$HIVE_HOME/bin
4、拷贝mysql驱动包到hive110/lib文件中


5、第一次运行hive要初始化
[root@gree139 conf]# schematool -dbType mysql -initSchema

6、在mysql查看是否创建hive源数据库成功
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| hive139            |
| mybatisdb          |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
7、启动hadoop

8、输入hive
[root@gree139 conf]# hive
> show databases

9、
[root@gree139 conf]# hive --service hiveserver2
后台启动
[root@gree139 conf]# nohup ../bin/hive --service hiveserver2 &

[root@gree139 hadoop]# beeline -u jdbc:hive2://192.168.153.139:10000
0: jdbc:hive2://192.168.153.139:10000>

hive> create database if not exists greedemo;
hive> show databases;
OK
default
greedemo
hive> select current_database();  当前始用的数据库
OK
default
hive> use greedemo;   数据库切换
OK
hive> select current_database();
OK
greedemo

hive> desc database greedemo;  查看数据库详情
OK
greedemo		hdfs://gree139:9000/user/hive/warehouse/greedemo.db	root	USER

hive> create table demo(id int, name string); 创建表
OK
Time taken: 0.076 seconds

hive> show tables;
OK
demo
Time taken: 0.028 seconds, Fetched: 1 row(s)

hive> insert into demo values(1,"zhangsan");
hive> insert into demo values(2,'lisi');

hive> desc demo;
OK
id                  	int                 	                    
name                	string   

hive> desc formatted demo;
# col_name            	data_type           	comment             
	 	 
id                  	int                 	                    
name                	string              	                    
	 	 
# Detailed Table Information	 	 
Database:           	greedemo            	 
Owner:              	root                	 
CreateTime:         	Tue Nov 09 11:35:28 CST 2021	 
LastAccessTime:     	UNKNOWN             	 
Protect Mode:       	None                	 
Retention:          	0                   	 
Location:           	hdfs://gree139:9000/user/hive/warehouse/greedemo.db/demo	 
Table Type:         	MANAGED_TABLE       	 
Table Parameters:	 	 
	COLUMN_STATS_ACCURATE	true                
	numFiles            	2                   
	numRows             	2                   
	rawDataSize         	16                  
	totalSize           	18                  
	transient_lastDdlTime	1636429923          
	 	 
# Storage Information	 	 
SerDe Library:      	org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe	 
InputFormat:        	org.apache.hadoop.mapred.TextInputFormat	 
OutputFormat:       	org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat	 
Compressed:         	No                  	 
Num Buckets:        	-1                  	 
Bucket Columns:     	[]                  	 
Sort Columns:       	[]                  	 
Storage Desc Params:	 	 
	serialization.format	1                   
Time taken: 0.055 seconds, Fetched: 32 row(s)

hive> insert overwrite table demo values(3,'wangwu');   覆盖

hive> create table demo2(id int, name string);
hive> alter table demo2 rename to demotwo;   修改表名
hive> alter table demotwo change name username string;  修改列属性
hive> alter table demotwo add columns(age int comment 'user age'); 添加列
hive> alter table demotwo add columns(addr string, email string);
hive> alter table demotwo replace columns(id int,username string);删除替换

hive> drop table demotwo;  删除表
hive> truncate table demo; 清空表里所有数据
hive> drop table demotwo;  删除表
hive> drop database greedemo cascade;  强制删库删表

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/457276.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号