Hive的安装步骤

Hive的安装步骤(本地安装模式)

1解压hivetar

$ tar -zxf hive-0.13.1-bin.tar.gz -C ../modules/

2.创建/tmphive数据仓库在HDFS之上的目录

$ bin/hdfs dfs -mkdir -p /user/hive/warehouse

$ bin/hdfs dfs -mkdir  /tmp      //默认已经创建了

修改目录的权限(增加组用户的写权限)

bin/hdfs dfs -chmod -R g+w  /user/hive/warehouse

bin/hdfs dfs -chmod -R g+w  /tmp

3.${HIVE_HOME}/conf/ 重命名生成配置文件

$ cp hive-env.sh.template hive-env.sh

$ cp hive-default.xml.template  hive-site.xml

$ cp  hive-log4j.properties.template hive-log4j.properties

Hive的安装步骤

4.${HIVE_HOME}/conf/ 修改hive-env.sh

JAVA_HOME=/opt/modules/jdk1.7.0_67

HADOOP_HOME=/opt/modules/hadoop-2.5.0

export HIVE_CONF_DIR=/hive的路径/conf

Hive的安装步骤

5、${HIVE_HOME}/conf/ 修改hive-site.xml

  <property>

  <name>javax.jdo.option.ConnectionURL</name>

  <value>jdbc:mysql://主机名:3306/metastore?createDatabaseIfNotExist=true</value>

  <description>JDBC connect string for a JDBC metastore</description>

</property>

<property>

  <name>javax.jdo.option.ConnectionDriverName</name>

  <value>com.mysql.jdbc.Driver</value>

  <description>Driver class name for a JDBC metastore</description>

</property>

 

<property>

  <name>javax.jdo.option.ConnectionUserName</name>

  <value>root</value>

  <description>username to use against metastore database</description>

</property>

 

<property>

  <name>javax.jdo.option.ConnectionPassword</name>

  <value>mysql密码</value>

  <description>password to use against metastore database</description>

</property>

Hive的安装步骤

6、修改hive-exec-log4j.properties

hive.log.dir=/hive的路径/logs

Hive的安装步骤

7拷贝jdbc驱动包到${HIVE_HOME}/lib

$ cp mysql-connector-java-5.1.34-bin.jar ../modules/apache-hive/lib/

Hive的安装步骤

Hive基本操作

一)启动Hive的条件

1.检查hadoop的相关进程

$ jps

26514 SecondaryNameNode

27934 ResourceManager

28033 NodeManager

26232 NameNode

28590 Jps

26329 DataNode

2.启动进入Hive CLI

${HIVE_HOME}/bin存放的hive的启动命令

$ bin/hive

启动之后检查mysql数据库中metastore数据库是否自动创建成功

在数据库自动生成metastore数据库,即配置成功

Hive的安装步骤

3.Hive表创建

//创建数据库

create database 数据库名;

Hive的安装步骤

//创建表

Eg:

--创建表

create table student(

id int comment 'id fo students',

name string comment 'name of students',

age int comment 'age of students',

gender string comment 'gender of students',

addr string

)

comment 'student'

row format delimited fields terminated by '\t';   //指定表格字段的分隔符

Hive的安装步骤

//加载数据

load data local inpath ‘文件目录’ into table 表名;

Hive的安装步骤

//查询数据

select * from student;

Hive的安装步骤

4.修改${HIVE_HOME}/conf/ 修改hive-site.xml

     显示当前所在的数据库名和查询结果的字段名

<property>

  <name>hive.cli.print.header</name>

  <value>true</value>

  <description>Whether to print the names of the columns in query output.</description>

</property>

 

<property>

  <name>hive.cli.print.current.db</name>

  <value>true</value>

  <description>Whether to include the current database in the Hive prompt.</description>

</property>

 

5、Select  * from 表名;   查询表

6、desc formatted 表名;   对表进行描述

7、alter table 旧表名 rename to 新表名;  修改表名 

8、alter table 表名 add columns(新字段名 字段类型);  添加新字段   

9、alter table 表名 add columns(新字段名 字段类型 comment ‘备注新字段’);  添加新字段,并加备注

10、alter table 表名 replace columns(旧字段名 字段类型,新字段名 字段类型 comment '备注');  修改字段名

11、drop table 表名;  删除表

12、dfs  -ls  /[目录];  Hive下查看dfs文件

13、!  -ls  /[目录];  Hive下查看Linux文件