Hive实践

准备

wget http://mirror.bit.edu.cn/apahce/hive/hive-0.11.0/hive-0.11.0-bin.tar.gz
tar -zxvf hive-0.11.0-bin.tar.gz
cd hive-0.11.0-bin
sudo vi /etc/profile

 - export HIVE_HOME=/usr/hive-0.11.0-bin
 - export PATH     =$PATH:$HIVE/bin
hadoop fs -mkdir /tmp
hadoop fs -mkdir /user/hive/warehouse
hadoop fs -chmod g+w /tmp
hadoop fs -chmod g+w /user/hive/warehouse
cp conf/hive-log4j-properties.template conf/hive-log4j/properties
local模式:set mapred.job.tracker=local;
hadoop集群模式:set mapred.job.traker=host001:9001;
hive 相关:
create table demo (key int,value string) row format delimited fields terminated by '='stored as textfile;
加载数据到表demo:
load data local inpath '/usr/hive-0.11.0-bin/data.txt'into table demo;
查询:
select * from demo;
select * from demo where key>=100 and key <=120;
seclet *,count(*)as fre from demo group by value order by fre desc;
  • 配置metastore 使用Mysql
sudo apt-get install mysql-server mysql-client 
grant all privileges on *.* to 'root'@'%'with grant option;
sudo vi /etc/mysql/my.cnf
 - 注释 bind-address =127.0.0.1
 - mysql -uroot -psyc
vi conf/hive-site.xml
<?xml version = "1.0"?>
<?xml-stylesheet type = "text/xsl" href ="configuration.xsl"?>
<configuration>
    <property>
        <name>javax.jdo.option.ConnectionURL</name>
        <value>jdbc:mysql://host001:3306/hive?createDatabaseIfNotExis=true</value>
    </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>
     <name>javax.jdo.option.ConnectionPassWord</name>
     <value>root</value>
    </property>
</configuration>

你可能感兴趣的:(Hive实践)