hadoop(十一)hive或者spark sql

hive

安装hive

Hive只在一个节点上安装即可

1.上传tar包

2.解压
    tar -zxvf hive-0.9.0.tar.gz -C /cloud/
3.配置mysql metastore(切换到root用户)
    配置HIVE_HOME环境变量
    
    查询以前安装的mysql相关包
    rpm -qa | grep mysql
    暴力删除这个包
    rpm -e mysql-libs-5.1.66-2.el6_3.i686 --nodeps
    
    mysql安装
    修改mysql的密码
    /usr/bin/mysql_secure_installation
    (注意:删除匿名用户,允许用户远程连接)
    登陆mysql
    mysql -u root -p

4.配置hive
    新增hive-site.xml
    添加如下内容:
    <property>
      <name>javax.jdo.option.ConnectionURL</name>
      <value>jdbc:mysql://weekend01:3306/hive?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>root</value>
      <description>password to use against metastore database</description>
    </property>
    
5.安装hive和mysq完成后,将mysql的连接jar包拷贝到$HIVE_HOME/lib目录下
    如果出现没有权限的问题,在mysql授权(在安装mysql的机器上执行)
   ./bin/mysql -h127.0.0.1 -uroot -proot
    #(执行下面的语句  *.*:所有库下的所有表   %:任何IP地址或主机都可以连接)
 grant all privileges on *.* to root@'%' identified by 'root';
 flush privileges;
 


6.建表(默认是内部表)
    create table trade_detail(id bigint, account string, income double, expenses double, time string) row format delimited fields terminated by '\t';
    建分区表
    create table td_part(id bigint, account string, income double, expenses double, time string) partitioned by (logdate string) row format delimited fields terminated by '\t';
    建外部表
    create external table td_ext(id bigint, account string, income double, expenses double, time string) row format delimited fields terminated by '\t' location '/td_ext';

7.创建分区表
    普通表和分区表区别:有大量数据增加的需要建分区表
    create table book (id bigint, name string) partitioned by (pubdate string) row format delimited fields terminated by '\t'; 

    分区表加载数据
    load data local inpath './book.txt' overwrite into table book partition (pubdate='2010-08-22');
    
    load data local inpath '/root/data.am' into table beauty partition (nation="USA");

    
    select nation, avg(size) from beauties group by nation order by avg(size);

 

使用hive

启动hive   ./bin/hive

常用命令

show tables;
drop table table_name;
select * from table_name;

load data local inpath '/home/hadoop/hive-0.12.0/test2.txt' overwrite into table t_order;导入本地数据

load data inpath '/home/hadoop/hive-0.12.0/test2.txt' overwrite into table t_order;导入hdfs数据

 

测试hive

1.创建hive数据库
create table t_order(id int,name string, rongling string,price double)
row format delimited
fields terminated by '\t';

2.创建测试数据

0000101    iphone6plus    64G    6888
0000102    xiaomi    64G    2388
0000103    iphone5s    64G    6888
0000104    mi3    64G    2388
0000105    huawei    64G    6888

注意数据间不是空格是tab

3.导入本地数据

load data local inpath '/home/hadoop/hive-0.12.0/test2.txt' overwrite into table t_order;
4.

select * from t_order;

select count(*) from t_order;

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值