您好,登錄后才能下訂單哦!
Hive只在一個節點上安裝即可
1.上傳tar包
2.解壓
tar -zxvf hive-0.9.0.tar.gz -C /cloud/
3.安裝mysql數據庫(切換到root用戶)(裝在哪里沒有限制,只有能聯通hadoop集群的節點)
mysql安裝僅供參考,不同版本mysql有各自的安裝流程
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的密碼
/usr/bin/mysql_secure_installation
(注意:刪除匿名用戶,允許用戶遠程連接)
登陸mysql
mysql -u root -p
4.配置hive
(a)配置HIVE_HOME環境變量 vi conf/hive-env.sh 配置其中的$hadoop_home
(b)配置元數據庫信息 vi hive-site.xml
添加如下內容:
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost: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>
</configuration>
5.安裝hive和mysq完成后,將mysql的連接jar包拷貝到$HIVE_HOME/lib目錄下
如果出現沒有權限的問題,在mysql授權(在安裝mysql的機器上執行)
mysql -uroot -p
#(執行下面的語句 *.*:所有庫下的所有表 %:任何IP地址或主機都可以連接)
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
FLUSH PRIVILEGES;
6. Jline包版本不一致的問題,需要拷貝hive的lib目錄中jline.2.12.jar的jar包替換掉hadoop中的
/home/hadoop/app/hadoop-2.6.4/share/hadoop/yarn/lib/jline-0.9.94.jar
啟動hive
bin/hive
----------------------------------------------------------------------------------------------------
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);
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。