Hive小白學習記錄 (一)基本操作

2021-10-08 02:28:38 字數 1601 閱讀 7115

1、建立乙個資料庫,mysql記錄資料庫得描述資訊,對應hdfs 上的資料庫資料夾

create database ;

e.g.

create database if not exists myhive

comment 'hive database demo'

location '/hdfs/directory' //指定資料庫在hdfs上的存放位置

with deproperties ('creator'='penny', 'date'='2020-7-14');

hive> create database myhive; //建立乙個資料庫 myhive

2、建立表 mysql記錄表的描述資訊,對應hdfs的表資料夾,不加修飾則是內部表【託管表managed_table 即由hive管理】

create table (id int, name string, age int,...)

comment 'table description'

row format delimited

fields terminated by ','

lines terminated by '\n'

stored as textfile;

e.g.

### 1. 在資料庫myhive 建立一張student表

hive> create table student( id int,

name string,

*** string,

age int,

department string

) comment 'table description' row format delimited fields terminated by ','

lines terminated by '\n'

stored as textfile;

2. create table if not exists student (

name string,

str_arr array,

t_struct,

t_map map,

t_map_arr>

)row format delimited fields by ','

map keys terminated by ':';

## 注 ##: 分隔符不能為 分號 ';'

3、從本地載入資料,即新增資料,——> 資料put 到hdfs上對應的資料夾中

load data local inpath '...[本地路徑]' overwrite into table // 省去 local 則是載入集群上的資料,該載入時移動

//overwrite 會覆蓋原來的資料

e.g.

//向表裡新增資料

hive> load data local inpath "/home/hadoop/student.txt" into table student;

3、使用新的資料庫myhive

hive> use myhive;

hive的基本操作(一)

hive的常用操作 1.檢視資料庫 show databases 2.使用 進入 資料庫 use db hive db hive是資料庫名 3.檢視資料庫內的資料表 show tables 4.檢視表結構 5.檢視表資料 6.向表中新增資料 insert into student values 2,...

Hive 一些操作記錄

1.建立 建立資料庫 create database database name 建立表 列按 分割 create table table name id int,name string row format delimited fields terminated by 建立分割槽表 列按 分割 按...

hive基本操作

1.顯示所有資料庫 show databases 2.使用某個資料庫 use xx xx表示某個資料庫名 3.顯示某資料庫下的所有表 show tables 4.檢視表結構 顯示各欄位 desc 表名 5.資料匯出到本地 在hive中操作 insert overwrite local directo...