hive install

Hive can only be installed on one node

 

1. Upload the tar package

 

2. Unzip

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

3. Configure mysql metastore (switch to root user)

Configure HIVE_HOME environment variable

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 

Change the password of mysql

/usr/bin/mysql_secure_installation

(Note: remove anonymous users, allow users to connect remotely)

log in to mysql

mysql -u root -p

 

4. Configure hive

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

Modify hive-site.xml (delete everything, leaving only one <property></property>)

Add the following:

<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. After installing hive and mysq, copy the mysql connection jar package to the $HIVE_HOME/lib directory

If there is a problem with no permissions, authorize it in mysql (execute on the machine where mysql is installed)

mysql -uroot -p

#(Execute the following statement *.*: All tables under all libraries %: Any IP address or host can connect)

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

FLUSH PRIVILEGES;

 

6. Create table (default is internal table)

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

create partition table

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

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 a partition table

The difference between a normal table and a partitioned table: if there is a large amount of data increase, a partitioned table needs to be built

create table book (id bigint, name string) partitioned by (pubdate string) row format delimited fields terminated by '\t'; 

 

Partitioned table loading data

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

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326854801&siteId=291194637