码迷,mamicode.com
首页 > 其他好文 > 详细

centos 7 上Hive-2.1.1的安装与基本操作

时间:2017-11-02 01:04:46      阅读:279      评论:0      收藏:0      [点我收藏+]

标签:查询   /etc/   ble   nbsp   span   string   基本   回车   直接   

首先安装mysql

  1. 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;

  1. 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中导入mysqljar,jar包在结尾

    f)        数据库的初始化  bin/schematool -initSchema -dbType mysql

  1. 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的安装与基本操作

标签:查询   /etc/   ble   nbsp   span   string   基本   回车   直接   

原文地址:http://www.cnblogs.com/cui0614/p/7769059.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!