Hive安裝配置

1.上傳tar包
2.解壓java

tar -zxvf hive-0.9.0.tar.gz -C /cloud/

3.配置mysql metastore(切換到root用戶)
配置HIVE_HOME環境變量node

rpm -qa | grep mysql
rpm -e mysql-libs-5.1.66-2.el6_3.i686 --nodeps
rpm -ivh MySQL-server-5.1.73-1.glibc23.i386.rpm 
rpm -ivh MySQL-client-5.1.73-1.glibc23.i386.rpm 

修改mysql的密碼mysql

/usr/bin/mysql_secure_installation

(注意:刪除匿名用戶,容許用戶遠程鏈接)
登錄mysql
mysql -u root -psql

4.配置hiveoop

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

修改hive-site.xml(刪除全部內容,只留一個<property></property>)
添加以下內容:spa

<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://hadoop00: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>123</value>
<description>password to use against metastore database</description>
</property>

5.安裝hive和mysq完成後,將mysql的鏈接jar包拷貝到$HIVE_HOME/lib目錄下
若是出現沒有權限的問題,在mysql受權(在安裝mysql的機器上執行)
mysql -uroot -p
#(執行下面的語句 *.*:全部庫下的全部表 %:任何IP地址或主機均可以鏈接)code

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123' WITH GRANT OPTION;
FLUSH PRIVILEGES;

6.建表(默認是內部表)orm

create table trade_detail(id bigint, account string, income double, expenses double, time string) row format delimited fields terminated by '\t';

建分區表server

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';

建外部表xml

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);
相關文章
相關標籤/搜索