一、HQL初步试用

1、创建一个student表

#创建一个student表
hive> create table student(id int, name string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';
OK
Time taken: 0.028 seconds
hive> show tables;
OK
bf_log
student
Time taken: 0.01 seconds, Fetched: 2 row(s) #因为数据是存在HDFS的文件中,ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' 就是指定数据之间的分隔符;

2、准备测试数据

[root@hadoop-senior datas]# touch student.txt

[root@hadoop-senior datas]# vim student.txt     #制表符分割
1001 zhangsan
1002 lisi
1003 wangwu

3、加载数据到hive表中

hive> load data local inpath '/opt/datas/student.txt' into table student;
Copying data from file:/opt/datas/student.txt
Copying file: file:/opt/datas/student.txt
Loading data to table default.student
Table default.student stats: [numFiles=1, numRows=0, totalSize=45, rawDataSize=0]
OK
Time taken: 0.222 seconds

4、查询

#查询全部,不会走MapReduce
hive> select * from student;
OK
1001 zhangsan
1002 lisi
1003 wangwu
Time taken: 0.023 seconds, Fetched: 3 row(s) #查询部分,就会走MapReduce
hive> select id from student;
Total jobs = 1
Launching Job 1 out of 1
Number of reduce tasks is set to 0 since there's no reduce operator
Starting Job = job_1554717689707_0003, Tracking URL = http://hadoop-senior.ibeifeng.com:8088/proxy/application_1554717689707_0003/
Kill Command = /opt/modules/hadoop-2.5.0/bin/hadoop job -kill job_1554717689707_0003
Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 0
2019-04-18 18:04:48,120 Stage-1 map = 0%, reduce = 0%
2019-04-18 18:04:53,240 Stage-1 map = 100%, reduce = 0%, Cumulative CPU 0.85 sec
MapReduce Total cumulative CPU time: 850 msec
Ended Job = job_1554717689707_0003
MapReduce Jobs Launched:
Job 0: Map: 1 Cumulative CPU: 0.85 sec HDFS Read: 268 HDFS Write: 15 SUCCESS
Total MapReduce CPU Time Spent: 850 msec
OK
1001
1002
1003
Time taken: 10.565 seconds, Fetched: 3 row(s)

二、安装mysql存储元数据

1、准备安装包

#卸载自带的mysql
[root@hadoop-senior softwares]# rpm -qa |grep mysql
mysql-libs-5.1.71-1.el6.x86_64 [root@hadoop-senior softwares]# rpm -e mysql-libs-5.1.71-1.el6.x86_64 --nodeps #
[root@hadoop-senior ~]# cd /opt/softwares/ [root@hadoop-senior softwares]# unzip mysql-libs.zip #
[root@hadoop-senior softwares]# cd mysql-libs [root@hadoop-senior mysql-libs]# ls
MySQL-client-5.6.24-1.el6.x86_64.rpm mysql-connector-java-5.1.27.tar.gz MySQL-server-5.6.24-1.el6.x86_64.rpm

2、安装启动

#安装server端
[root@hadoop-senior mysql-libs]# rpm -ivh MySQL-server-5.6.24-1.el6.x86_64.rpm #会生成随机密码,在/root/.mysql_secret里 [root@hadoop-senior ~]# cat /root/.mysql_secret
# The random password set for the root user at Fri Apr 19 09:29:24 2019 (local time): O9zwV6WQljcMkzRa #安装client
[root@hadoop-senior mysql-libs]# rpm -ivh MySQL-client-5.6.24-1.el6.x86_64.rpm #启动
[root@hadoop-senior mysql-libs]# service mysql start
Starting MySQL. [确定] [root@hadoop-senior mysql-libs]# service mysql status
MySQL running (24085) [确定] [root@hadoop-senior mysql-libs]# netstat -ntlp |grep 3306
tcp 0 0 :::3306 :::* LISTEN 24085/mysqld

3、连接mysql,改密码

#改密码
[root@hadoop-senior mysql-libs]# mysql -uroot -pO9zwV6WQljcMkzRa #密码是刚才自动生成的
......
mysql> set password=password('123456');
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye #新密码连接
[root@hadoop-senior mysql-libs]# mysql -uroot -p123456
......
mysql>

4、授权mysql的root用户

#
[root@hadoop-senior ~]# hostname
hadoop-senior.ibeifeng.com #连入mysql操作
mysql> grant all privileges on *.* to root@'%' identified by '123456';
Query OK, 0 rows affected (0.00 sec) mysql> grant all privileges on *.* to 'root'@'hadoop-senior.ibeifeng.com' identified by '123456' with grant option;
Query OK, 0 rows affected (0.00 sec) mysql> select User,Host,Password from user;
+------+----------------------------+-------------------------------------------+
| User | Host | Password |
+------+----------------------------+-------------------------------------------+
| root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| root | hadoop-senior.ibeifeng.com | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| root | 127.0.0.1 | *D25D1C957F2E56F330D565256AE9D88C49E7194D |
| root | ::1 | *D25D1C957F2E56F330D565256AE9D88C49E7194D |
| root | % | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+------+----------------------------+-------------------------------------------+
5 rows in set (0.00 sec) mysql> delete from user where User='root' and Host='hadoop-senior.ibeifeng.com';
Query OK, 1 row affected (0.00 sec) mysql> delete from user where User='root' and Host='127.0.0.1';
Query OK, 1 row affected (0.00 sec) mysql> delete from user where User='root' and Host='::1';
Query OK, 1 row affected (0.00 sec) mysql> delete from user where User='root' and Host='localhost';
Query OK, 1 row affected (0.00 sec) mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec) mysql> select User,Host,Password from user;
+------+------+-------------------------------------------+
| User | Host | Password |
+------+------+-------------------------------------------+
| root | % | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+------+------+-------------------------------------------+
1 row in set (0.00 sec) mysql> exit;

1.5 Hive初步使用和安装MySQL的更多相关文章

  1. Hive初步使用、安装MySQL 、Hive配置MetaStore、配置Hive日志《二》

    一.Hive的简单使用 基本的命令和MySQL的命令差不多 首先在 /opt/datas 下创建数据  students.txt 1001 zhangsan 1002 lisi 1003 wangwu ...

  2. Hive基础概念、安装部署与基本使用

    1. Hive简介 1.1 什么是Hive Hives是基于Hadoop的一个数据仓库工具,可以将结构化的数据文件映射为一张数据库表,并提供类SQL查询功能. 1.2 为什么使用Hive ① 直接使用 ...

  3. ubuntu安装mysql遇到的坑----解决Mysql报错缺少libaio.so.1

    最近学习大数据,涉及到hive的部分需要安装mysql,于是就在linux环境下尝试安装,对于我这个linux小白来说,中间遇到很多坑爹问题,在这里做一个记录. 我参考的mysql安装博客: http ...

  4. spark安装mysql与hive

    第一眼spark安装文件夹lib\spark-assembly-1.0.0-hadoop2.2.0.jar\org\apache\spark\sql下有没有hive文件夹,假设没有的话先下载支持hiv ...

  5. 安装MySQL与安装Hive

    安装mysql 检查是否安装mysql: rpm -qa |grep mysql 删除已经安装的mysql: rpm -e mysql-libs-5.1.71-1.el6.x86_64 报错:因为my ...

  6. 60分钟内从零起步驾驭Hive实战学习笔记(Ubuntu里安装mysql)

    本博文的主要内容是: 1. Hive本质解析 2. Hive安装实战 3. 使用Hive操作搜索引擎数据实战 SparkSQL前身是Shark,Shark强烈依赖于Hive.Spark原来没有做SQL ...

  7. hive0.13.1安装-mysql server作为hive的metastore

    hive0.13.1在hadoop2.4.1伪分布式部署上安装过程 环境:redhat enterprice 6.5 +hadoop2.4.1+hive0.13.1+mysql单节点伪分布式部署 相关 ...

  8. HIVE 2.1.0 安装教程。(数据源mysql)

    前期工作 安装JDK 安装Hadoop 安装MySQL 安装Hive 下载Hive安装包 可以从 Apache 其中一个镜像站点中下载最新稳定版的 Hive, apache-hive-2.1.0-bi ...

  9. Hive 安装 & Mysql 安装

    安装Hive && mysql (1)安装Hive Hive安装所需要的依赖(安装Hive前必须先安装jdk.hadoop) 1)jdk1.6以上 2)Hadoop要启动 未安装jdk ...

随机推荐

  1. do export method of oracle all database tables with dmp files.

    usually we need to export the database tables to backup and others use. So we must know what to do e ...

  2. git 忽略文件的三种方式

    1. 在项目目录下新建.gitignore文件并添加规则 特点:此种方式的忽略规则只局限于本项目目录及其子目录,并且.gitignore文件会被提交到远程仓库进行共享忽略规则. 2. 在.git/in ...

  3. 发送邮件程序报错454 Authentication failed以及POP3和SMTP简介

    一.发现问题 在测试邮件发送程序的时候,发送给自己的QQ邮箱,程序报错454 Authentication failed, please open smtp flag first. 二.解决问题 进入 ...

  4. Mac OS command line TestNG - “Cannot find class in classpath” error

    直接eclipse执行.xml文件可以正确执行 在mac下执行却总报错: [TestNG] [Error] Cannot find class in classpath 最后解决办法,classpat ...

  5. MFC学习之Radio---MFC Radio按钮组的使用例子

    首先我们要完成一个功能,在一个添加新用户的场景里,通过Radio按钮来判断用户选择的是管理员还是普通用户. 要使用Radio组的功能首先我们必须作如下设置: 1.2个Radio按钮的ID号不同,但是他 ...

  6. 实现单击列表头对ListView的动态排序

    排序是根据列的类型来的,就ID列来说,int类型的排序结果是3,5,17,而如果你把该列类型改为string,结果就会是17,3,5,如果你定义列的时候不加类型,默认是string,如果是自定义类型, ...

  7. java socket相关的timeout

    1 java socket的两个timeout 一个是connect timeout,即建立连接的timeout,另外一个是so timeout,是读取数据的timeout.这两个timeout都是因 ...

  8. yuicompressor

      yui/yuicompressor: YUI Compressor https://github.com/yui/yuicompressor    YUI Compressor 详细介绍 YUI ...

  9. 判断Java数组是否包含某个值

    下面给出四种方式,其中最有效率的还是loop方式,有兴趣的话可以测试一下: 代码如下: public boolean findStr(String[] args,String str){ boolea ...

  10. go 文件上传

    package main import ( "fmt" "io" "io/ioutil" "log" "net ...