不在折腾---hive-0.13.1-bin

时间:2023-12-18 14:10:26

Hive只在一个节点安装即可

上传tar包

解压

> tar zxvf hive-0.13.1-bin.tar.gz

配置mysql

* 检查MySQL是否安装:rpm -qa | grep mysql
卸载MySQL:rpm -e --nodeps mysql-libs-5.1.66-2.el6_3.i686
安装MySQL服务端: rpm -ivh MySQL-server-5.1.73-1.glibc23.i386.rpm
安装MySQL客户端:rpm -ivh MySQL-client-5.1.73-1.glibc23.i386.rpm
启动MySQL服务: service mysql start/status
* 修改MySQL的密码
登录: mysql -uroot -p(安装时随机生成的密码)
修改: set PASSWORD=PASSWORD('123456')
* 删除匿名账号,允许用户远程连接
查询账号:select user,host,password from user
更新host允许远程连接:update user set host = '%' where user='root' and host='localhost';
删除其余三个:delete from user where ...
刷新权限:flush privileges;

配置hive

*cp hive-default.xml.template hive-site.xml
修改hive-site.xml(删除所有内容,只留一个<property></property>)
添加如下内容:
<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>123456</value>
<description>password to use against metastore database</description>
</property>

连接

* 将MySQL的连接驱动jar包拷贝到$HIVE_HOME/lib目录下
* 如果出现没有权限的问题,在mysql授权(在安装mysql的机器上执行)
mysql -uroot -p
#(执行下面的语句 *.*:所有库下的所有表 %:任何IP地址或主机都可以连接)
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123' WITH GRANT OPTION;
FLUSH PRIVILEGES;

启动

* $HIVE_HOME/bin/hive

常用命令

* 建表(默认是内部表)
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'; * 创建分区表 * 普通表和分区表区别:有大量数据增加的需要建分区表
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);