欢迎投稿

今日深度:

Hive的安装步骤,

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


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


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>


6、修改hive-exec-log4j.properties

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


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

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


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数据库,即配置成功


3.Hive表创建

//创建数据库

create database 数据库名;


//创建表

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';   //指定表格字段的分隔符


//加载数据

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


//查询数据

select * from student;


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文件


www.htsjk.Com true http://www.htsjk.com/hive/41343.html NewsArticle Hive的安装步骤, Hive 的安装步骤(本地安装模式) 1 解压 hive 的 tar 包 $ tar -zxf hive-0.13.1-bin.tar.gz -C ../modules/ 2. 创建 /tmp 和 hive 数据仓库在 HDFS 之上的目录 $ bin/hdfs dfs -mkdir -p /user/hive/...
相关文章
    暂无相关文章
评论暂时关闭