HIve安装前提是mysql已经安装成功。安装步骤上个笔记有
切换hadoop用户 :su - hadoop
xftp打开目录: /home/hadoop/soft
上传hive二进制文件:tar -xvf apache-hive-1.2.2-bin.tar.gz
移动解压的文件:mv apache-hive-1.2.2-bin ../install/hive
修改环境变量
vim /etc/profile
export HIVE_HOME=/home/hadoop/install/hive
export PATH=$PATH:$HIVE_HOME/bin
保存并使环境变量立即生效
source /etc/profile
HIVE存放元数据(将HDFS文件,映射为HIVE里面的表结构定义信息--->元数据信息)
数据信息是存储在HDFS上的
HIVE--->MYSQL需要JDBC的支持,我们需要把JDBC包拷贝到hive/lib目录下
cp /soft/mysql-connector-java-5.1.38.jar /home/hadoop/install/hive/lib
-------------------------------------------------MySQL赋权操作----------------------------------------
创建hive数据库
mysql> create database hive default character set latin1;
Query OK, 1 row affected (0.04 sec)
创建hive用户并赋予权限
mysql> grant all on *.* to 'hive'@'%' identified by 'hive';
Query OK, 0 rows affected (0.04 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.03 sec)
查询 mysql.user信息
mysql> select user,host,password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host | password |
+------+-----------+-------------------------------------------+
| root | localhost | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| root | % | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| hive | % | *4DF1D66463C18D44E3B001A8FB1BBFBEA13E27FC |
+------+-----------+-------------------------------------------+
3 rows in set (0.00 sec)
创建hive配置文件
vim hive-site.xml
————————————————————————————————————————————
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://192.168.2.10:3306/hive?characterEncoding=UTF-8</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hive</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>hive</value>
</property>
<!-- hdfs hive存储数据的目录 -->
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/usr/hive/warehouse</value>
</property>
<!-- 本地元数据服务 -->
<property>
<name>hive.metastore.local</name>
<value>true</value>
</property>
</configuration>
——————————————————————————————————————————
显示所有数据库
show databases;
可以建立数据库
create database test1;
切换数据库
use test1;
建立表employee
CREATE TABLE employee (
eid int,
name String,
salary String,
destination String)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n'
STORED AS TEXTFILE;
查看所有表
show tables;