Hive基本操作語句

2021-08-10 03:01:08 字數 2936 閱讀 5884

show databases;——顯示所有資料庫

use db_ame;——進入指定資料庫

show tables;——顯示當前資料庫中的所有資料表

show partitions;——顯示所有分割槽

show table extended;——顯示表的擴充套件資訊

show table properties;——顯示表的所有屬性

show indexes;——顯示所有索引

show create table;——顯示建立表的語句

show columns;——顯示所有列

show functions;——顯示所有函式

describe function func_name;——顯示函式用法

show granted roles and privileges;——顯示所有角色與許可權

show locks;——顯示鎖

show conf;——顯示配置檔案

show transactions;——顯示事務

describe databases;——顯示某資料庫的詳情

describe tables/view/column;——顯示表/檢視/列的詳情

describe partition;——顯示分割槽的詳情

hive;quit;exit

use db_name;——切換資料庫

show databases;——檢視所有資料庫

show tables;——檢視所有表

create database db_name;——建立資料庫

drop database if exists db cascade;——刪除資料庫(包含資訊)

create table tb_name (col1 int, col2 string, col3 double);——建立三個不同型別屬性的表

alter table tb_name rename to new_name;——更新表名

alter table tb_name add columns (new_col int);——新增一列

alter table tb_name replace columns(col1 int, col3 double);——刪除col2列

drop table tb_name;——刪除表

dfs -rmr/user/hive/warehouse/records——刪除表中資料,但保持表結構定義

load data local inpath 『/home/hadoop/input/ncdc/micro-tab/sample.txt』 overwrite into table records;——從本地檔案載入資料

select sales., things. from sales join things on (sales.id = things.id);——內連線

select sales., things. from sales left outer join things on (sales.id = things.id);——外連線

6.1 資料—>mysql workbench—>hive(sqoop方法)

首先匯入自己機器&&&.&&.&&&.&&:3306中mysql new_schema資料庫中的test1表到遠端連線的hive指定的資料庫ussd中,並在ussd中新建coursetest表

sqoop import – connect jdbc:

mysql://***.**.***.**:3306/new_schema –username root –password 123456 –table test1 –hive-import;

然後,將關係型資料的表結構複製到hive中:

sqoop create-hive-table --connect jdbc:

mysql:// ***.**.***.**:3306/test --table username --username root --password 123456 --hive-table test;

最後,匯入自己機器的mysql new_schema資料庫中的test1表到集群本地機器中hive指定的資料庫ussd中,並在ussd中新建coursetest表

sqoop import  –hive-import– connect jdbc:

mysql://***.**.***.**:3306/new_schema –-username root –-password 123456 –-table test1 –-hive-database ussd –hive-table coursetest;

6.2 資料—>伺服器電腦—>hive(load方法)

首先,用winscp 登陸伺服器電腦&&&.&&.&&&.&&:10240(root:password),將.csv檔案資料複製到root電腦

然後用putty_v0…或者vncviewer 登入到該電腦(root:sduasp),用load語句將資料匯入。首先進入指定資料庫,建表:

create table table_name(attr1 datatype, attr2 datatype, ……)row format delimited fields terminated by 『\t』
然後用load語句匯入資料到表中:

load data local inpath 『/home/cyf/transitdata/dataname.csv』 overwrite into table table_name;
匯入結束後,若需過濾資料,則只能用select語句:

insert overwrite table table_name select * from table_name where col_1 !=』******x』;

hive基本操作

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

hive 基本操作

檢視表的詳細資訊 desc 表名 desc formatted 表名 建立外部表 create external table emp ext empno int,ename string,job string,mgr int,hiredate string,sal double,comm doubl...

HIVE基本操作

hive操作 一 建立分割槽 乙個表可以有多個分割槽,為避免過多的小檔案,建議只能對離散字段進行分割槽 create table if not exists stocks ymd date,price open float,price high float,price low float,price...