docker run -d \ -p 10000:10000 \ -p 10002:10002 \ --env SERVICE_NAME=hiveserver2 \ --name hive4 apache/hive:4.0.0-beta-1
http://localhost:10002/
./beeline -u "jdbc:hive2://localhost:10000/default"
tar zxvf apache-hive-3.1.3-bin.tar.gz cd apache-hive-3.1.3-bin
此时运行会报错
./bin/hive # Cannot find hadoop installation: $HADOOP_HOME or $HADOOP_PREFIX must be set or hadoop must be in the path
./sbin/start-dfs.sh export HADOOP_HOME=/home/wy/workspace/hadoop/hadoop-3.3.6 ./bin/hive
conf/hive-site.xml
<property> <name>hadoop.proxyuser.username.groups</name> <value>*</value> </property> <property> <name>hadoop.proxyuser.username.hosts</name> <value>*</value> </property>
create table testDB(id int, name string, age int); show databases; show tables;
点击下载
hadoop fs -mkdir -p /sogou/work hadoop fs -put sogou.10w.utf8.flt /sogou/work hadoop fs -ls /sogou/work show databases; create database sogou; use sogou; show tables; create external table sogou.sogou_tab(ts string,uid string,keyword string,rank int,sorder int, url string,year int,month int,day int,hour int) row format delimited fields terminated by '\t' stored as textfile location '/sogou/work'; drop table sogou.sogou_tab; show create table sogou.sogou_tab; describe sogou_tab; # 创建带分区的表: create external table sogou.sogou_partition(ts string,uid string,keyword string,rank int,sorder int,url string)partitioned by (year int,month int,day int,hour int) row format delimited fields terminated by '\t' stored as textfile; set hive.exec.dynamic.partition.mode=nonstrict; insert overwrite table sogou.sogou_partition partition(year,month,day,hour) select * from sogou.sogou_tab;
修改hive环境变量文件,指定Hadoop的安装路径
cd /opt/server/apache-hive-3.1.2-bin/conf cp hive-env.sh.template hive-env.sh vim hive-env.sh # 加入以下内容 HADOOP_HOME=/opt/server/hadoop-3.1.0
Hive 是一个基于 Hadoop 的数据仓库基础设施工具,通常使用外部数据库(如 MySQL)作为其元数据存储(metastore)。但是,如果您不想使用 MySQL 或其他外部数据库作为 Hive 的 metastore,Hive 也提供了一种内嵌 Derby 数据库的方式来作为元数据存储。要配置 Hive 使用内嵌 Derby 数据库作为 metastore,请按照以下步骤进行操作:
schematool -initSchema -dbType derby
数据库操作
create database test;--创建数据库 show databases;--列出所有数据库 use test;--切换数据库
表操作
-- 建表 create table t_student(id int,name varchar(255)); -- 插入一条数据 insert into table t_student values(1,"potter"); -- 查询表数据 select * from t_student;
在执行插入数据的时候,发现插入速度极慢,sql执行时间很长,花费了26秒,并且显示了MapReduce程序的进度