标签(空格分隔): hive
1) Hive 如何配置与Hadoop 关联,进行创建表,加载数据测试
2) 在Linux下安装MySQL数据库
3) 配置Hive元数据存储在MySQL中,查看相关元数据表信息
4) 熟悉基本的DML和DDL语句(创建数据库、表及加载数据和基本查询语句Select)
hadoop,spark,kafka交流群:224209501
1,相关文档及环境要求
1.1,相关文档
- 官网:http://hive.apache.org
- 文档:hive home getting start
- 下载:download
1.2,环境要求:
- java 1.7
- Hadoop 2.x (preferred)
- 本文配置的环境是centos6.4
2,安装hive
2.1 解压eapache-hive-0.13.1-bin.tar.gz
$tar -zxvf apache-hive-0.13.1-bin.tar.gz ./
2.2 设置HIVE_HOME为hive安装目录
$ cd hive-0.13.1
$ export HIVE_HOME={
{
pwd}}
2.3 添加HIVE_HOME到系统PATH中
$ export PATH=$HIVE_HOME/bin:$PATH
3,运行hive
3.1 创建相关目录
$bin/hdfs dfs -mkdir /tmp
$bin/hdfs dfs -mkdir -p /user/hive/warehouse
$bin/hdfs dfs -chmod g+w /tmp
$bin/hdfs dfs -chmod g+w /user/hive/warehouse
3.2 修改配置文件
在hive-env.xml文件中添加如下内容:
# Set HADOOP_HOME to point to a specific hadoop install directory
HADOOP_HOME=/opt/modules/hadoop-2.5.0/
# Hive Configuration Directory can be controlled by:
export HIVE_CONF_DIR=/opt/modules/hive-0.13.1/conf
3.3 运行hive命令界面
(1).进入hive shell
//hive安装目录
$bin/hive
(2).创建table 名为student。
>use default;
>create table student(id int,name string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';
>show tables;
执行结束后:
(2).上传数据
$vi stu.txt
//内容:
1001 sean
1002 jike
1003 tony
//上传数据到表中
>load data local inpath '/opt/datas/stu.txt' into table student;
(3).查看表中数据
>select * from student;
执行结束后:
(4).查看表中某一个列的数据
>select id from student;
执行结束后:
3.4 运行 HiveServer2 and Beeline
//hive安装目录
$bin/hiveserver2
$bin/beeline -u jdbc:hive2://$HS2_HOST:$HS2_PORT
4,安装mySQL
4.1 联网安装,使用yum
设置自动获取IP地址
4.2 替换系统镜像源
$ cd /etc/yum.repos.d
$ sudo mv CentOS-Base.repo CentOS-Base.repo.bak
$ sudo touch CentOS6-Base-163.repo
$ sudo vi CentOS6-Base-163.repo
//安装完成后执行
$ sudo yum clean all
4.3 安装MYSQL
$ sudo yum list|grep mysql
$ sudo yum install mysql-server -y
4.4 启动Mysql
$ sudo service mysqld status
$ sudo service mysqld start
4.5 设置密码
# /usr/bin/mysqladmin -u root password '123456'
4.8 设置开机启动mysqld
$sudo chkconfig mysqld on
$sudo chkconfig --list |grep mysqld
执行结束后
4.7 测试
$ mysql -uroot -p123456
> show databases ;
> use test ;
> show tables ;
5,hive常用属性配置
5.1 Hive hive-site.xml配置
首先创建vi hive-site.xml,并输入任意字符。
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://hadoop-miao.host.com/metastore_db?createDatabaseIfNotExist=true</value>
<description>JDBC connect string for a JDBC metastore</description>