1. 程式人生 > >HIVE的常用操作-建庫和表-插入資料

HIVE的常用操作-建庫和表-插入資料

hive的安裝(遠端模式)   點選開啟連結

使用hive
-----------------------

啟動hadoop

啟動hive

建立資料庫:

create database myhive;
檢視資料庫:

hive (default)> show databases;
OK
database_name
default
myhive
資料準備:employees.txt

1201    Gopal    45000    Technical manager
1202    Manisha    45000    Proof reader
1203    Masthanvali    40000    Technical writer
1204    Krian    40000    Hr Admin
1205    Kranthi    30000    Op Admin
在myhive庫中建立表

    use myhive;

hive (myhive)> create table myhive.employee (eud int,name String,salary String,destination String) COMMENT 'Employee table' ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' STORED AS TEXTFILE;
OK
Time taken: 0.109 seconds
向hive中載入資料 (local模式)   查詢資料

hive (myhive)> load data local inpath '/home/hadoop/data/employees.txt' into table employee;
Loading data to table myhive.employee
OK
Time taken: 0.288 seconds
hive (myhive)> select * from employee;
OK
employee.eud    employee.name    employee.salary    employee.destination
1201    Gopal    45000    Technical manager
1202    Manisha    45000    Proof reader
1203    Masthanvali    40000    Technical writer
1204    Krian    40000    Hr Admin
1205    Kranthi    30000    Op Admin
Time taken: 0.128 seconds, Fetched: 5 row(s)
載入資料到hive  (實際載入到hdfs)

非local模式把資料載入到hive

資料準備:    data.txt

1206    tom    5000    Proof reader
1207    liming    40000    Technical writer
[[email protected] data]$ hadoop fs -mkdir /data
[[email protected] data]$ hadoop fs -put ./data.txt /data

hive (myhive)> load data  inpath '/data/data.txt' into table employee1;
Loading data to table myhive.employee1
OK
Time taken: 0.274 seconds
hive (myhive)> select * from employee1;
OK
employee1.eud    employee1.name    employee1.salary    employee1.destination
1206    tom    5000    Proof reader
1207    liming    40000    Technical writer
Time taken: 0.103 seconds, Fetched: 2 row(s)
在local模式的情形中進行如下操作

[[email protected] data]$ hadoop fs -put ./data.txt /user/hive/warehouse/myhive.db/employee
[[email protected] data]$ hadoop fs -cat  /user/hive/warehouse/myhive.db/employee/data.txt
1206    tom    5000    Proof reader
1207    liming    40000    

在同一路徑資料文字格式相同資料載入成功(並非需要load data..............)進行資料的載入

hive (myhive)> select * from employee;
OK
employee.eud    employee.name    employee.salary    employee.destination
1206    tom    5000    Proof reader
1207    liming    40000    Technical writer
1201    Gopal    45000    Technical manager
1202    Manisha    45000    Proof reader
1203    Masthanvali    40000    Technical writer
1204    Krian    40000    Hr Admin
1205    Kranthi    30000    Op Admin
Time taken: 0.162 seconds, Fetched: 7 row(s)
向employee表中插入資料 -mapreduce-job        

**  (HIVE:    支援插入, 不支援刪除和更新

hive (myhive)> insert into employee(eid,name) values(1208,'jack')

             > ;
FAILED: SemanticException 1:21 'eid' in insert schema specification is not found among regular columns of myhive.employee nor dynamic partition columns.. Error encountered near token 'name'
hive (myhive)> insert into employee(eid,name) values(1208,'jack');
FAILED: SemanticException 1:21 'eid' in insert schema specification is not found among regular columns of myhive.employee nor dynamic partition columns.. Error encountered near token 'name'
hive (myhive)> insert into employee(eud,name) values(1208,'jack');
WARNING: Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
Query ID = hadoop_20180629105054_e4e30a0f-92b7-42b5-8ecb-3a5fe41d516b
Total jobs = 3
Launching Job 1 out of 3
Number of reduce tasks is set to 0 since there's no reduce operator
Starting Job = job_1530235955590_0001, Tracking URL = http://master:8088/proxy/application_1530235955590_0001/
Kill Command = /usr/local/soft/hadoop-2.7.3/bin/hadoop job  -kill job_1530235955590_0001
Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 0
2018-06-29 10:51:11,738 Stage-1 map = 0%,  reduce = 0%
2018-06-29 10:51:22,753 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 2.59 sec
MapReduce Total cumulative CPU time: 2 seconds 590 msec
Ended Job = job_1530235955590_0001
Stage-4 is selected by condition resolver.
Stage-3 is filtered out by condition resolver.
Stage-5 is filtered out by condition resolver.
Moving data to directory hdfs://master:9000/user/hive/warehouse/myhive.db/employee/.hive-staging_hive_2018-06-29_10-50-54_840_2892277479385925233-1/-ext-10000
Loading data to table myhive.employee
MapReduce Jobs Launched: 
Stage-Stage-1: Map: 1   Cumulative CPU: 2.59 sec   HDFS Read: 4375 HDFS Write: 87 SUCCESS
Total MapReduce CPU Time Spent: 2 seconds 590 msec
OK
_col0    _col1    _col2    _col3


hadoop fs -lsr /user/

簡單操作    (在hive中執行shell命令      本地)

hive (myhive)> !ls /home/hadoop/data;
1901
1902
data.txt
employees.txt
hive (myhive)> !cat data.txt;
cat: data.txt: 沒有那個檔案或目錄
Command failed with exit code = 1
hive (myhive)> !cat /home/hadoop/data/data.txt;
1206    tom    5000    Proof reader
1207    liming    40000    Technical 
其他的shell命令在hive中的用法與上面的相同

(在hive中執行shell命令      HDFS)

hive (default)> dfs -ls /;
Found 7 items
drwxr-xr-x   - hadoop supergroup          0 2018-06-29 10:58 /data
drwxr-xr-x   - hadoop supergroup          0 2018-06-26 22:27 /hbase
drwxr-xr-x   - hadoop supergroup          0 2018-06-27 20:52 /home
drwxr-xr-x   - hadoop supergroup          0 2018-06-24 20:54 /input
drwxr-xr-x   - hadoop supergroup          0 2018-06-28 22:54 /mapreduce
drwx------   - hadoop supergroup          0 2018-06-29 10:50 /tmp
drwxr-xr-x   - hadoop supergroup          0 2018-06-25 15:49 /user

--------------------- 
作者:qq_41028958 
來源:CSDN 
原文:https://blog.csdn.net/qq_41028958/article/details/80853089 
版權宣告:本文為博主原創文章,轉載請附上博文連結!

相關推薦

HIVE常用操作--插入資料

hive的安裝(遠端模式)   點選開啟連結 使用hive ----------------------- 啟動hadoop 啟動hive 建立資料庫: create database myhive; 檢視資料庫: hive (default)> s

php資料庫操作-建立以及插入資料

以上我們正確連線到了mysql資料庫,本文將進一步建立資料庫,表,在表中填充資料。 大家知道連線上資料庫才能進行操作,同樣的程式碼搬過來 <?php /* * 資料庫操作*(建立資料庫,表,插入資料,插入多條資料) * * To change the tem

手工空間資料檔案非自動擴充套件引起的錯誤:ORA-01653: unable to extend* in tablespace*

手工建庫時,未將表空間資料檔案設定為自動擴充套件引起的錯誤:ORA-01653: unable to extend * in tablespace * 的解決:檢視資料庫alert日誌檔案時,發現出現大量如下的錯誤: Sun Dec 01 10:00:42 2013 ORA

HIVE基礎操作(命令,資料匯出匯入等)--持續更新

1.show databases; 2.show tables; 3.show tables in 資料庫名;(不在對應資料庫下可查到想要的表名) 4.show tables in hive 'tom*'; 查詢在hive資料庫下,tom開頭的表名。 5.desc extended tablenam

MySQL<數據的基本操作>

字段值 提高 主鍵約束 dex pri 表示 span 整數 describe 數據庫和表的基本操作 數據庫基礎知識 創建數據庫   就是在數據庫系統中劃分一塊存儲數據的空間   CREATE DATABASE itcast; 查看數據庫   SHOW CREATE DAT

java編寫創數據的程序

row blog 編寫 開始 creates throw pub 打開 import 本文示例可見一斑了,主要是通過Java對SQL語句進行操作,和普通的增刪改查的原理是一樣的: import java.sql.*; public class Test {

mysql的相關操作

ear dml 枚舉類型 mysqld grant 文件路徑 關系數據庫 通用 非關系型 一、數據庫介紹1、數據庫的由來我們之前所學,數據要想永久保存,都是保存於文件中,毫無疑問,一個文件僅僅只能存在於某一臺機器上,這樣就帶來了許多問題:(1)程序所有的組件就不可能運行在一

Mysql --操作

擴展 charset 系統 index 選擇 有一種 spl 單獨 one 庫的增刪改查 系統數據庫 創建數據庫 數據庫的相關操作 表的操作 存儲引擎介紹(有點多 很啰唆) 表的介紹 表的操作 一、系統數據庫 查看系統庫: show databases

【MySQL】2、MySQL 創數據

數值 加鎖 字母 發送 lint 引擎 code font reat 2.MySQL 創建數據庫和表 2.1、創建數據庫 CREATE DATABASE 語句用於在 MySQL 中創建數據庫。 CREATE DATABASE database_name 為了讓 PH

Sql 的基本操作、基本數據類型

time 復制表結構 小數 ask oot fault 年份 sign 基本數據 一、數據庫的基本操作   基本操作:   1、查看當前數據庫:show databases;   2、進入到指定的數據庫:use [數據庫名],   數據庫的增刪改查:   1、創建數據庫:c

SQL Server語句創數據——並設置主外鍵關系

_id stun .cn rim 執行 sco 技術 core 變量 簡單的創建數據庫的 SQL 語句: 1 use master 2 go 3 4 if exists(select * from sysdatabases where name=‘Test‘)

數據的基本操作

一個 刪除 from databases on() 增刪改查 use des 數據庫版本 數據庫的基本操作 -- 鏈接數據庫 mysql -uroot -p mysql -uroot -pmysql -- 退出數據庫 exit/quit/ctrl+d -- sql語

小白mysql入門操作(2)的檢視、增加、刪除

首先 檢視資料庫:show databases;(注意:語句後面有分號“;”,如果沒有分號伺服器不會有任何響應,因為mysql中的語句是以分號結尾的) 例如: 我們可以看見現有的幾個資料庫,其中information_schema,mysql,performance

實驗二 數據的創與管理

gin 數據庫名 order esc mil 數據庫 default 長度 spa 實驗二 數據庫和表的創建與管理 創建用於企業管理的員工管理數據庫,數據庫名為YGGL中,YGGL數據庫中包括三個表:Employees(員工信息表)、Departments(部門信息表

如何從零開始快速學習sql sever 資料庫基本操作-/-刪/

環境配置 1.安裝sql sever 資料庫到本地,我用的是sql sever2014版,至於如何安裝請百度吧,學會用搜索工具很重要的,我就不在此囉嗦了。 2.連結上資料庫。 看到紅色框裡面就是各個資料庫名,有些是sql sever 自帶的,有些是我自己建立的,本文主要講述

django重新創數據

避免 數據庫 裏的 以及 刪除數據 虛擬 記錄 數據 刪除 1 刪除數據庫中的django_migration 表 以及 刪除你要重新導的表 2 將你要導的那個app中的migrate 文件刪除掉 3 進行虛擬導入 migrate --fake 虛擬導入會重新生成d

數據操作

隔離 into 特點 數值類型 ces http 單選 速查 size 一.庫操作 1.創建庫   create database 庫名[charset utf8];  創建庫[字符集為utf8] 默認為utf8 2.查看庫   show databases;  查看所有庫

python裡的字串常用方法格式化操作

字串(str)的一些內建操作方法:capitalize() 將字串的首個字母變為大寫casefold() 把全部的大寫全部變為小寫center(width) 將字串居中, 並用空格填充長度至width的新字串的長度count(sub[, start[, end]]) 返回s

MySQL數據的相關操作

utf 結束 var table drop 所在 查看 數據 表名 執行如下命令,查看系統庫 show databases; 求救語法: help create database; 創建數據庫語法 CREATE DATABASE 數據庫名 charset utf8;

靜默刪除數據

dbca 靜默建庫 很多時候客戶現場或測試環境不一定有xm等圖形工具,新建庫或刪除庫需要通過命令行進行。靜默建庫:[email protected]/* */>select * from v$version where rownum<2; BANNER -----------