centos 7 上Hive-2.1.1的安装与基本操作
Posted 砖治不服
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos 7 上Hive-2.1.1的安装与基本操作相关的知识,希望对你有一定的参考价值。
首先安装mysql
- 1. 在线安装mysql
a) yum install mysql
b) yum install mysql-devel
c) 安装mariadb yum install mariadb-server mariadb
d) systemctl enable mariadb #设置开机启动
e) systemctl start mariadb #开启服务
f) mysql -u root -p 首次登陆不需要密码,直接回车即可进入
g) 修改mysql密码 set password = password(‘root‘);
h) 开启mysql的远程登录 grant all privileges on *.* to ‘root‘ @‘%‘ identified by ‘root‘;
i) 刷新 flush privileges;
- 2. Hive的安装(采用的是本地模式安装)
a) 在/opt/software/hive 下解压hive tar -xvf *** (安装包可以私聊我要,不知道怎么上传安装包)
b) 修改 /etc/profile 文件 vi /etc/profile
# Hive environment
export HIVE_HOME=/opt/software/hive/apache-hive-2.1.1-bin
export PATH=$HIVE_HOME/bin:$HIVE_HOME/conf:$PATH
c) 使环境变量生效 source /etc/profile
d) 在hive/conf目录下创建hive-site.xml文件 mkdir hive-site.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true</value> </property> <property> <name>javax.jdo.option.ConnectionDriverName</name> <value>com.mysql.jdbc.Driver</value> </property> <property> <name>javax.jdo.option.ConnectionUserName</name> <value>root</value> </property> <property> <name>javax.jdo.option.ConnectionPassword</name> <value>123456</value> </property> <property> <name>hive.metastore.schema.verification</name> <value>true</value> <description> Enforce metastore schema version consistency. True: Verify that version information stored in metastore matches with one from Hive jars. Also disable automatic schema migration attempt. Users are required to manully migrate schema after Hive upgrade which ensures proper metastore schema migration. (Default) False: Warn if the version information stored in metastore doesn‘t match with one from in Hive jars. </description> <property> <name>hive.metastore.uris</name> <value>thrift://localhost:9083</value> </property> </property> </configuration>
e) 在$HIVE_HOME/lib中导入mysql的jar包,jar包在结尾
f) 数据库的初始化 bin/schematool -initSchema -dbType mysql
- 3. Hive的操作和mysql基本一致,所以基本操作就不介绍
hive导入数据四种方式
(加local是本地,overwrite into会覆盖)
从本地文件系统中导入数据到Hive表
create table wyp (id int, name string,age int, tel string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ‘\t‘ STORED AS TEXTFILE;
load data local inpath ‘wyp.txt‘ into table wyp;
HDFS上导入数据到Hive表
load data inpath ‘/home/wyp/add.txt‘ into table wyp;
从别的表中查询出相应的数据并导入到Hive表中
create table test(id int, name string,tel string) partitioned by (age int) ROW FORMAT DELIMITED FIELDS TERMINATED BY ‘\t‘ STORED AS TEXTFILE;
insert into table test partition (age=‘25‘) select id, name, tel from wyp;
在创建表的时候通过从别的表中查询出相应的记录并插入到所创建的表[称为CTAS(create table .. as select)]
create table test4 as select id, name, tel from wyp;
Hive数据导出三种方式
导出到本地文件系统
insert overwrite local directory ‘/home/wyp/wyp‘
生成的文件名是000000_0.
导出到HDFS中
insert overwrite directory ‘/home/wyp/hdfs‘
导出到Hive的另一个表中
insert into table test partition (age=‘25‘) select id, name, tel from wyp;
以上是关于centos 7 上Hive-2.1.1的安装与基本操作的主要内容,如果未能解决你的问题,请参考以下文章