一、Hive基本概念

  • 1、Hive简介

    • Hive是一个基于hadoop的开源数据仓库工具,用于存储和处理海量结构化数据。它把海量数据存储于hadoop文件系统,而不是数据库,但提供了一套类数据库的数据存储和处理机制,并采用HQL(类SQL)语言对这些数据进行自动化管理和处理。我们可以把Hive中海量结构化数据看成一个个的表,而实际上这些数据是分布式存储在HDFS中的。Hive经过对语句进行解析和转换,最终生成一系列基于hadoop的map、reduce任务,通过执行这些任务完成数据处理。
    • Hive不仅提供了一个熟悉SQL的用户所能熟悉的编程模型,还消除了大量的通用代码,甚至是那些有时是不得不使用java编写的令人棘手的代码。因此,Hive对于hadoop是非常重要的。
    • 其优点是学习成本低,可以通过类SQL语句快速实现简单的MapReduce统计,不必开发专门的MapReduce应用,十分适合数据仓库的统计分析,应用开发灵活而高效。
    • Hive的特点
      • 可扩展

        • Hive可以自由的扩展集群的规模,一般情况下不需要重启服务
      • 延展性
        • Hive支持用户自定义函数,用户可以根据自己的需求来实现自己的函数
      • 容错性
        • 良好的容错性,节点出现问题时SQL仍可完成执行
    • Hive与传统数据库的对比:
对比项 Hive 传统数据库
查询语言 HQL SQL
数据存储 HDFS Raw Device or Local FS
执行 MapReduce Excutor
执行延迟
处理数据规模
索引 0.8版本后加入位图索引 有复杂的索引
  • 2、数据仓库(如Hive)与数据库(如MySQL)

    • 数据仓库DW包含很多个数据库DB,每个DB又包含很多表

      • 数据库的个数可以是很多的
      • 每个库中的表也可以很多
      • 每个表中的字段也可以很多
    • 如要很快定位到表中的几条记录,先得找到数据库(DB),再找到表,然后再找到字段。因为数据库是以B+树的树形结构存储的。
    • 数据仓库的元信息,是非常重要的,一般情况下存放在一个关系型(或者其他类型)数据库中。
  • 3、Hive的信息存放
    • Hive的元信息是存放在mysql数据库(默认是derby数据库,但替换成了mysql数据库)
    • Hive的数据信息存放HDFS中,在目录hive> dfs -ls /user/hive/warehouse的对应database中

二、Hive的下载与安装

打开网址http://mirrors.hust.edu.cn/apache/

根据自己所需下载版本


先把下载的hive压缩包上传到linux,然后输入命令开始解压安装

[admin@master ~]$ tar zxvf apache-hive-1.2.2-bin.tar.gz


安装成功

三、MySQL数据库下载与安装(rpm方式安装)

  • Linux下MySQL数据库的安装有两种方式

    • rpm方式安装
    • yum方式安装
      此处以rpm方式安装为例。

1、安装包下载

查看linux操作系统版本和系统内核版本

[root@master ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@master ~]# uname -r
3.10.0-1160.el7.x86_64

打开网址https://dev.mysql.com/downloads/mysql/

根据自己需求选择安装版本(也可以选择bundle套件进行下载)

2、开始安装

如果下载的文件是.tar格式,将下载的mysql安装包上传到linux系统中,则参考如下命令进行解压。

[admin@master ~]$ tar -xf MySQL-5.6.21-1.el7.x86_64.rpm-bundle.tar

此处我的不需解压

登录root用户

[admin@master ~]$ su - root
密码:
上一次登录:日 2月 28 01:40:57 CST 2021pts/0 上

检查是否安装过mysql

[root@master ~]# rpm -qa | grep -i mysql

如果有安装,则输入命令删除掉,如果没有则跳过此操作。mysql-libs为文件开头。

[root@master ~]# yum -y remove mysql-libs*

检查CentOS操作系统自带的数据库mariadb-lib并卸载

[root@master ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@master ~]# yum remove -y mariadb-libs-5.5.68-1.el7.x86_64

检查用于生成可以自动的配置软件源代码包以适应多种UNIX 系统的shell脚本的工具autoconf是否有安装,如无安装则输入命令安装

[root@master ~]# rpm -qf /usr/bin/autoconf
[root@master ~]# yum -y install autoconf

切换到文件解压存放的目录,并查看文件

[root@master ~]# cd /home/admin

输入命令安装server

[root@master admin]# rpm -ivh MySQL-server-5.6.22-1.el7.x86_64.rpm


输入命令安装client

[root@master admin]# rpm -ivh MySQL-client-5.6.22-1.el7.x86_64.rpm


输入命令安装devel

[root@master admin]# rpm -ivh MySQL-devel-5.6.22-1.el7.x86_64.rpm

3、修改配置文件位置

默认情况下,配置文件放在如下目录

[admin@master ~]$ cd /usr/share/mysql


现拷贝到/etc目录下

[root@master mysql]# cp my-default.cnf /etc/my.cnf
[root@master mysql]# cd /etc
[root@master mysql]# ll

4、初始化MySQL

输入命令进行初始化

[root@master ~]# /usr/bin/mysql_install_db

5、启动MySQL以及登录MySQL

输入命令启动MySQL

[root@master ~]# service mysql start


启动成功后。可以输入命令查看密码(默认情况下没有密码),这一步可以选择跳过

[root@master ~]# cat /root/.mysql_secret
cat: /root/.mysql_secret: 没有那个文件或目录

第一次登录,连续点击enter即可

[root@master ~]# mysql -uroot -p
Enter password:

登录后,可以进行密码修改

mysql> set password = password("123456")

输入命令exit退出,重新登录

mysql> exit
Bye
[root@master ~]# mysql -uuser -p123456
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'user'@'localhost' (using password: YES)
[root@master ~]# mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.22 MySQL Community Server (GPL)Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

6、设置远程登录

显示所有的databases

mysql> show databases;


进入mysql库

mysql> use mysql;


显示所有的tables

mysql> show tables;


找到表user并显示表的字段

mysql> describe user;


SQL语句查询表

mysql> select host,user,password from user;


可以看到root中master、127.0.0.1、::1都是空白密码,而localhost是有密码。那么现在把root中都设置为localhost同样的密码

mysql> update user set password = password("123456") where user = "root";
Query OK, 3 rows affected (0.00 sec)
Rows matched: 4  Changed: 3  Warnings: 0mysql> update user set password = password("123456") where user = "root" and host = "localhost";
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0

输入命令进行

mysql> flush privileges;


退出,重新登录,重新查询表。可以看到已经设置成功,密码一致

mysql> exit
Bye
[root@master ~]# mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.6.22 MySQL Community Server (GPL)Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| innodb_index_stats        |
| innodb_table_stats        |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| servers                   |
| slave_master_info         |
| slave_relay_log_info      |
| slave_worker_info         |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
28 rows in set (0.00 sec)mysql> select host,user,password from user;
+-----------+------+-------------------------------------------+
| host      | user | password                                  |
+-----------+------+-------------------------------------------+
| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| master    | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| 127.0.0.1 | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| ::1       | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| localhost |      |                                           |
| master    |      |                                           |
+-----------+------+-------------------------------------------+
6 rows in set (0.00 sec)mysql>

7、设置开机自启动

先查看MySQL自启动的状态(默认情况下自启动是开的,不用设置了)

[root@master ~]# chkconfig --list | grep mysql;


如果要开或者关,则输入如下命令
开:

[root@master ~]# chkconfig mysql on

关:

[root@master ~]# chkconfig mysql off

8、MySQL的默认安装位置

  • (1)数据库目录。例如创建了一个databases,即可在这个目录中查看到。
`[root@master ~]# cd /var/lib/mysql
  • (2)配置文件目录
[root@master ~]# cd /usr/share/mysql
  • (3)相关命令目录
[root@master ~]# cd /usr/bin
  • (4)启动脚本
[root@master ~]# /etc/init.d/mysql

9、修改字符集和数据存储路径等

修改数据存放路径、mysql.s’ock路径以及默认编码utf-8等在配置文件/etc/my.cnf中修改

10、查看字符集

mysql> show variables like '%char%';

mysql> show variables like '%collation%';

11、创建一个普通用户

先登录数据库

[root@master ~]# mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.6.22 MySQL Community Server (GPL)Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>

输入命令创建

mysql> grant all on *.* to hadoop@'%' identified by 'hadoop';
mysql> grant all on *.* to hadoop@'localhost' identified by 'hadoop';
mysql> grant all on *.* to hadoop@'master' identified by 'hadoop';

重新刷新

mysql> flush privileges;


退出重新使用hadoop登录即可验证是否成功

mysql> exit
Bye
[root@master ~]# mysql -uhadoop -phadoop
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.6.22 MySQL Community Server (GPL)Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>

12、创建一个存放hive的数据的数据库hive_db

mysql> create database hive_db;

四、配置Hive

  • Hive内部提供了一个Derby的数据库,用来存储Hive数据仓库的元信息

    • Derby数据库的数据存放在内存中,当节点宕机时,则存放在Derby数据库中的数据就会丢失,并且Derby数据库不支持并发
    • 所以Hive数据仓库的元信息要换存到本地(支持并发的MySQL数据库)

如下配置Hive连接MySQL

1、配置hive-site.xml文件

切换admin用户
输入命令进入目录

[root@master ~]# su - admin
上一次登录:日 3月 14 13:24:05 CST 2021pts/0 上
[admin@master ~]$ ll
总用量 314372
-rw-rw-r--.  1 admin admin       240 12月  7 06:46 _
drwxrwxr-x.  8 admin admin       159 3月  13 21:11 apache-hive-1.2.2-bin
-rw-rw-r--.  1 admin admin  90859180 3月  13 21:09 apache-hive-1.2.2-bin.tar.gz
-rw-rw-r--.  1 admin admin        14 2月  24 22:04 a.txt
drwxr-xr-x. 10 admin admin       161 2月  21 21:24 hadoop-2.5.2
-rw-rw-r--.  1 admin admin 147197492 2月  21 14:18 hadoop-2.5.2.tar.gz
drwxrwxr-x.  3 admin admin        17 2月  28 15:31 hadoopdata
-rw-rw-r--.  1 admin admin  19903532 3月  14 02:10 MySQL-client-5.6.22-1.el7.x86_64.rpm
-rw-rw-r--.  1 admin admin   3533816 3月  14 02:10 MySQL-devel-5.6.22-1.el7.x86_64.rpm
-rw-rw-r--.  1 admin admin  60406096 3月  14 02:10 MySQL-server-5.6.22-1.el7.x86_64.rpm
drwxrwxr-x.  2 admin admin        29 3月   2 23:28 sogou.500w
drwxrwxr-x.  3 admin admin        37 2月  21 23:20 test
drwxr-xr-x.  2 admin admin         6 12月  7 02:35 公共
drwxr-xr-x.  2 admin admin         6 12月  7 02:35 模板
drwxr-xr-x.  2 admin admin         6 12月  7 02:35 视频
drwxr-xr-x.  2 admin admin         6 12月  7 02:35 图片
drwxr-xr-x.  2 admin admin         6 12月  7 02:35 文档
drwxr-xr-x.  2 admin admin         6 12月  7 02:35 下载
drwxr-xr-x.  2 admin admin         6 12月  7 02:35 音乐
drwxr-xr-x.  2 admin admin         6 12月  7 02:35 桌面
[admin@master ~]$ cd apache-hive-1.2.2-bin
[admin@master apache-hive-1.2.2-bin]$ ls
bin  conf  examples  hcatalog  lib  LICENSE  NOTICE  README.txt  RELEASE_NOTES.txt  scripts
[admin@master apache-hive-1.2.2-bin]$ cd conf
[admin@master conf]$ ls
beeline-log4j.properties.template  hive-default.xml.template  hive-env.sh.template  hive-exec-log4j.properties.template  hive-log4j.properties.template  ivysettings.xml
[admin@master conf]$

创建hive-site.xml文件

[admin@master conf]$ vim hive-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration><property><name>hive.metastore.local</name><value>true</value></property><property><name>javax.jdo.option.ConnectionURL</name><value>jdbc:mysql://master:3306/hive_meta?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>hadoop</value></property><property><name>javax.jdo.option.ConnectionPassword</name><value>hadoop</value></property>
</configuration>
~

2、hive连接mysql的驱动

把下载的jar包上传的Linux系统并放到该目录下

[admin@master ~]$ cd apache-hive-1.2.2-bin
[admin@master apache-hive-1.2.2-bin]$ cd lib
[admin@master lib]$ cp /home/admin/mysql-connector-java-5.1.28.jar ./

3、配置hive的环境变量

输入命令,配置hive的环境变量

[admin@master ~]$ vim ~/.bash_profile


执行配置

[admin@master ~]$ source ~/.bash_profile
4、启动hive

输入命令启动hive

[admin@master ~]$ hive

启动成功

启动后可以查看hive的list

hive> list> ;
Query returned non-zero code: 1, cause: Usage: list [FILE|JAR|ARCHIVE] [<value> [<value>]*]

显示hive的数据库,可以看到只有一个默认库

hive> show databases;
OK
default
Time taken: 0.969 seconds, Fetched: 1 row(s)

也可以在hive创建sougou数据库

hive> create database sougou;
OK
Time taken: 0.262 seconds
hive> show databases;
OK
default
sougou
Time taken: 0.016 seconds, Fetched: 2 row(s)

打开一个新页签,登录mysql验证,可以看到hive_meta数据库中自动创建了一些hive默认表

[admin@master ~]$ mysql -uhadoop -phadoop
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 50
Server version: 5.6.22 MySQL Community Server (GPL)Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases-> ;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| hive_db            |
| hive_meta          |
| mysql              |
| performance_schema |
| test               |
+--------------------+
6 rows in set (0.01 sec)mysql> use hive_meta;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
mysql> show tables;
+---------------------------+
| Tables_in_hive_meta       |
+---------------------------+
| BUCKETING_COLS            |
| CDS                       |
| COLUMNS_V2                |
| DATABASE_PARAMS           |
| DBS                       |
| FUNCS                     |
| FUNC_RU                   |
| GLOBAL_PRIVS              |
| PARTITIONS                |
| PARTITION_KEYS            |
| PARTITION_KEY_VALS        |
| PARTITION_PARAMS          |
| PART_COL_STATS            |
| ROLES                     |
| SDS                       |
| SD_PARAMS                 |
| SEQUENCE_TABLE            |
| SERDES                    |
| SERDE_PARAMS              |
| SKEWED_COL_NAMES          |
| SKEWED_COL_VALUE_LOC_MAP  |
| SKEWED_STRING_LIST        |
| SKEWED_STRING_LIST_VALUES |
| SKEWED_VALUES             |
| SORT_COLS                 |
| TABLE_PARAMS              |
| TAB_COL_STATS             |
| TBLS                      |
| VERSION                   |
+---------------------------+
29 rows in set (0.00 sec)
mysql>


其中的一个表DBS,可以查看到我们刚新建的sougou数据库以及查看DBS的表结构

mysql> select * from DBS;

mysql> describe hive_meta.DBS;


根据URI可以看到sougou.db在HDFS的存放位置

[admin@master ~]$ hadoop fs -ls /user
Found 2 items
drwxr-xr-x   - admin supergroup          0 2021-02-28 15:31 /user/admin
drwxr-xr-x   - admin supergroup          0 2021-03-20 10:44 /user/hive
[admin@master ~]$ hadoop fs -ls /user/hive
Found 1 items
drwxr-xr-x   - admin supergroup          0 2021-03-20 10:44 /user/hive/warehouse
[admin@master ~]$ hadoop fs -ls /user/hive/warehouse
Found 1 items
drwxr-xr-x   - admin supergroup          0 2021-03-20 10:44 /user/hive/warehouse/sougou.db
[admin@master ~]$

Hadoop学习笔记(16)Hive的基本概念、Hive的下载与安装、MySQL数据库下载与安装相关推荐

  1. Hadoop学习笔记—16.Pig框架学习

    Hadoop学习笔记-16.Pig框架学习 一.关于Pig:别以为猪不能干活 1.1 Pig的简介 Pig是一个基于Hadoop的大规模数据分析平台,它提供的SQL-LIKE语言叫Pig Latin, ...

  2. 十四、Hadoop学习笔记————Zookeeper概述与基本概念

    顺序一致性:严格按照顺序在zookeeper上执行 原子性:所有事物请求的结果,在整个集群的应用情况一致 单一视图:无论从哪个服务器进入集群,看到的东西都是一致的 可靠性:服务端成功响应后,状态会 一 ...

  3. hadoop学习笔记-目录

    以下是hadoop学习笔记的顺序: hadoop学习笔记(一):概念和组成 hadoop学习笔记(二):centos7三节点安装hadoop2.7.0 hadoop学习笔记(三):hdfs体系结构和读 ...

  4. Linux 学习笔记16 信号量

    Linux 学习笔记16 信号量Semaphore 信号量概念 信号量(或信号灯)是一种用于提供不同进程间或一个给定进程的不同线程间同步手段的原语. 信号量是控制进程(或线程)同步(谁先执行,谁后执行 ...

  5. Hadoop学习笔记—18.Sqoop框架学习

    Hadoop学习笔记-18.Sqoop框架学习 一.Sqoop基础:连接关系型数据库与Hadoop的桥梁 1.1 Sqoop的基本概念 Hadoop正成为企业用于大数据分析的最热门选择,但想将你的数据 ...

  6. Hadoop学习笔记—20.网站日志分析项目案例(一)项目介绍

    Hadoop学习笔记-20.网站日志分析项目案例(一)项目介绍 网站日志分析项目案例(一)项目介绍:当前页面 网站日志分析项目案例(二)数据清洗:http://www.cnblogs.com/edis ...

  7. cocos2d-x学习笔记16:记录存储1:CCUserDefault

    cocos2d-x学习笔记16:记录存储1:CCUserDefault 一.简述 CCUserDefalt作为NSUserDefalt类的cocos2d-x实现版本,承担了cocos2d-x引擎的记录 ...

  8. Hadoop学习笔记—15.HBase框架学习(基础知识篇)

    Hadoop学习笔记-15.HBase框架学习(基础知识篇) HBase是Apache Hadoop的数据库,能够对大型数据提供随机.实时的读写访问.HBase的目标是存储并处理大型的数据.HBase ...

  9. 【学习笔记】 科目一之概念篇

    [学习笔记] 科目一之概念篇 概念题方法 1)抓重点:科目一设计知识范围太广,不要妄想所有知识点都复习到,这是不可能的,我们的目标是45分几个而不是考高分,复习时间有限,所以要学会抓重点,比如法律条文 ...

最新文章

  1. HGOI 20190709 题解
  2. Android获取当前时间
  3. Jsp内置对象及EL表达式的使用
  4. python的类和对象——类的静态字段番外篇
  5. 阅读类APP体验好不好?可从这些指标衡量
  6. c/c++ 结构体前加不加typedef有什么区别?
  7. C语言程序读写文件(文件内存一个十进制数,每读一次数值加一)
  8. 开源特训营 - Lesson 6 - 如何提交一个合格的PR
  9. 案例 github_2019年12月Github上最热门的Java开源项目,速来围观!
  10. 牛客OI周赛4-提高组 C 战争(war)
  11. matlab如何分解矩阵,Matlab中矩阵的分解
  12. 平板边界层内的流速分布实验
  13. 北京内推 | 百度增强现实技术部招聘虚拟人算法实习生
  14. 刚培训的java程序员怎么找工作,快来看鸭~
  15. Pod2g已发现可完美越狱iOS 5的漏洞
  16. 怎么查找计算机的内存卡,如何查看自己电脑的内存卡的牌子?
  17. 织梦php模板在哪个文件夹,织梦主要文件夹目录及模板文件说明
  18. 京东开源人脸识别项目faceX-zoo
  19. 维基解密想帮助苹果、Google 对抗 CIA 黑客入侵
  20. 基于Python实现的论坛帖子情感分析

热门文章

  1. quickpcb添加pcb库_QuickPcb2005元件库(QuickPcb集成元件库)V1.0 最新版
  2. c++——vc++中的六种Runtime Library的类型
  3. 这次不鸽!PDF第四版终于出炉!
  4. Openfiler 基本介绍
  5. 【002】EIS测试_#LIB
  6. LQ0215 绳圈【DP】
  7. 绿色自适应网址发布页源码
  8. 启蒙之路 | 跨平台渲染引擎之路:拨云见日
  9. 怎样下载网页flash
  10. 大龄程序员 “敢问路在何方?”