hive的安装配置笔记

1.上传hive安装包

2.解压

3.配置Hive(在一台机器上即可)

bash 复制代码
    mv hive-env.sh.template hive-env.sh

4.运行hive

发现内置默认的metastore存在问题(1.换执行路径后,原来的表不存在了。2.只能有一个用户访问同一个表)

5.配置mysql的metastore

查询以前安装的mysql相关包

bash 复制代码
        rpm -qa | grep mysql

暴力删除这个包

bash 复制代码
        rpm -e mysql-libs-5.1.66-2.el6_3.i686 --nodeps

上传两个mysql的rpm包

bash 复制代码
        rpm -ivh MySQL-server-5.1.73-1.glibc23.i386.rpm 
        rpm -ivh MySQL-client-5.1.73-1.glibc23.i386.rpm

执行命令设置mysql

bash 复制代码
        /usr/bin/mysql_secure_installation

授权:

bash 复制代码
        GRANT ALL PRIVILEGES ON hive.* TO 'root'@'%' IDENTIFIED BY '123' WITH GRANT OPTION;
        FLUSH PRIVILEGES

在hive当中创建两张表

sql 复制代码
        create table trade_detail (id bigint, account string, income double, expenses double, time string) row format delimited fields terminated by '\t';
        create table user_info (id bigint, account string, name  string, age int) row format delimited fields terminated by '\t';

将mysql当中的数据直接导入到hive当中

sql 复制代码
        sqoop import --connect jdbc:mysql://192.168.1.10:3306/itcast --username root --password 123 --table trade_detail --hive-import --hive-overwrite --hive-table trade_detail --fields-terminated-by '\t'
        sqoop import --connect jdbc:mysql://192.168.1.10:3306/itcast --username root --password 123 --table user_info --hive-import --hive-overwrite --hive-table user_info --fields-terminated-by '\t'

创建一个result表保存前一个sql执行的结果

sql 复制代码
        create table result row format delimited fields terminated by '\t' as select t2.account, t2.name, t1.income, t1.expenses, t1.surplus from user_info t2 join (select account, sum(income) as income, sum(expenses) as expenses, sum(income-expenses) as surplus from trade_detail group by account) t1 on (t1.account = t2.account);
sql 复制代码
        create table user (id int, name string) row format delimited fields terminated by '\t'

将本地文件系统上的数据导入到HIVE当中

sql 复制代码
        load data local inpath '/root/user.txt' into table user;

创建外部表

sql 复制代码
        create external table stubak (id int, name string) row format delimited fields terminated by '\t' location '/stubak';

创建分区表

普通表和分区表区别:有大量数据增加的需要建分区表

sql 复制代码
        create table book (id bigint, name string) partitioned by (pubdate string) row format delimited fields terminated by '\t'; 

分区表加载数据

sql 复制代码
        load data local inpath './book.txt' overwrite into table book partition (pubdate='2023-08-22');
相关推荐
霍小毛4 小时前
Hive 与 TiDB 在大数据解析场景中的对比分析
大数据·hive·tidb
Ray.19982 天前
Flink 中的滚动策略(Rolling Policy)
hive·flink·spark·kafka·big data
Ray.19982 天前
深入理解 Flink 中的 .name() 和 .uid() 方法
hive·hadoop·flink·spark·kafka
红队it3 天前
【Spark+Hadoop】基于Spark大数据小说数据分析推荐系统(完整系统源码+数据库+开发笔记+详细部署教程+虚拟机分布式启动教程)✅
大数据·人工智能·hive·分布式·spark
chimchim664 天前
hive开窗函数边界值ROWS BETWEEN 和 RANGE BETWEEN区别
数据仓库·hive·hadoop
千叶真尹4 天前
通过Hive小文件合并(CombineHiveInputFormat)减少80%的Map任务数
数据仓库·hive·hadoop
先睡4 天前
Spring MVC配置文件
数据仓库·hive·hadoop
知初~5 天前
出行项目案例
hive·hadoop·redis·sql·mysql·spark·database
我要用代码向我喜欢的女孩表白7 天前
hive迁移补数脚本细粒度 表名-分区唯一键
数据仓库·hive·hadoop
隔壁老登7 天前
查询hive指定数据库下所有表的建表语句并生成数据字典
数据库·hive·hadoop