什么是hive
hive是数据仓库工具,本身不存储数据,真实数据存储在hdfs上,元数据(表的列及表的基本信息)存储在数据库中,计算过程在mapreduce,本身没有存储引擎,所以启动hive的前提是hdfs、yarn和数据库要启动起来(hive自带默认数据库derby,我们一般不使用该数据库,derby不支持并发访问)。hive本质是:将HQL转化成MapReduce程序
hive安装配置
hive下载地址:http://hive.apache.org/
hive-env.sh文件配置(该文件在hive安装目录下的conf下):两个环境变量
export HADOOP_HOME=/opt/module/hadoop-2.7.2
export HIVE_CONF_DIR=/opt/module/hive/conf
mysql安装配置(rpm安装,centos6)
查看mysql是否安装,如果安装需要卸载
查看是否安装:rpm -qa|grep mysql
卸载:rpm -e --nodeps mysql-libs-5.1.73-7.el6.x86_64
安装服务器端:rpm -ivh MySQL-server-5.6.24-1.el6.x86_64.rpm
查看mysql生成的随机密码:cat /root/.mysql_secret
启动mysql:service mysql start
查看mysql状态:service mysql status
安装mysql客户端:rpm -ivh MySQL-client-5.6.24-1.el6.x86_64.rpm
连接mysql(p后的6个0是密码,未修改前的密码在/root/.mysql_secret下面):mysql -uroo -p00000
修改密码:SET PASSWORD=PASSWORD('000000');
配置只要是root用户+密码,在任何主机上都能登录MySQL数据库:
修改 在database为mysql的user表:update user set host='%' where host='localhost'
刷新:flush privileges;
hive元数据配置到mysql
1.将mysql驱动包拷贝到hive/lib 目录下
2.编辑hive-site.xml (该文件放置在hive/conf文件下)
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://192.168.206.102:3306/metastore?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>000000</value>
<description>password to use against metastore database</description>
</property>
</configuration>
重新启动hive后再次打开mysql:show databases; 会看到metastore 的databse
hive基本操作
启动bin/hive 在这个客户端执行hive操作
增删改操作类似mysql,创建表的数据类型和mysql有区别
本地文件导入hive
创建数据库表:create table student(id int,name string) row format delimited fields terminated by '\t';
hive导入操作:load data local inpath '/opt/module/datas/student.txt' into table student;
hive数据仓库位置配置(在hive-site.xml中添加如下配置)
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
<description>location of default database for the warehouse</description>
</property>
配置同组用户有执行权限:bin/hdfs dfs -chmod g+w /user/hive/warehouse
hive查询信息显示配置如下
<property>
<name>hive.cli.print.header</name>
<value>true</value>
</property>
<property>
<name>hive.cli.print.current.db</name>
<value>true</value>
</property>