hive資料庫的常用命令操作

2021-10-23 21:36:50 字數 2093 閱讀 3052

啟動hive

hive
啟動成功就進入了hive的shell操作介面。

檢視資料庫

hive> show databases;

okdefault

hive1

hive2

time taken: 0.031 seconds, fetched: 3 row(s)

檢視表
hive> show tables;

okhelloworld

time taken: 0.056 seconds, fetched: 1 row(s)

切換資料庫
hive> use hive1;

oktime taken: 0.013 seconds

1.建立庫,新增備註,新增資料庫屬性
hive> create database if not exists hive2

> comment "this is a test database"

> with dbproperties(

'creator'

='test','date'

='2020-08-27');

oktime taken: 0.036 seconds

2.建立表,定義2個字段
hive> create table helloworld(id int,name string);ok

time taken: 0.381 seconds

3.檢視表結構
hive> desc helloworld;

okid int

name string

time taken: 0.27 seconds, fetched: 2 row(s)

4.建立表,使用空格分隔
hive> create table hello(in int,name string)

> row format delimited fields terminated by '\t';ok

time taken: 0.309 seconds

5.匯入本地資料到hive的表,覆蓋表內容

(本質就是將本地檔案上傳到hive資料庫)

overwrite表示覆蓋相同的資料,不寫overwrite會新增相同的資料。

> overwrite into table hello;

loading data to table hive2.hello

[warning] could not update stats.

oktime taken: 23.727 seconds

6.檢視表

hive>

select * from hello;

ok1 aa

2 bb

3 cc

time taken: 0.045 seconds, fetched: 3 row(s)

7.顯示表所在的資料庫

當前會話有效:

set hive.cli.print.current.db=true;
全域性配置有效

在hive-site.xml中增加如下配置:

>

>

hive.cli.print.current.dbname

>

>

truevalue

>

property

>

重啟hive檢視預設資料庫的提示資訊,成功:

hive (default)

> use hive2; ok

time taken: 1.144 seconds

hive (hive2)

>

hive 二 hive常用命令操作

三 常用命令 四 常用資料型別 這節將介紹hive常用命令操作,包括資料庫操作 表操作 資料操作等。hive的採用了類sql的語法,也稱為hql。2.1 以互動方式執行命令bin hive此時可以在命令列中輸入set hive.cli.print.current.db true 可以顯示當前選中資料...

MySQL資料庫常用命令操作

登入 mysql uroot p123456 建立資料庫 create database 資料庫名 切換資料庫 use 資料庫名 查詢資料庫中所有的資料表 show tables 建立新的資料表 create table 資料表名 欄位名 資料型別,欄位名 資料型別,非空約束 not null 建表...

mysql資料庫的常用操作 常用命令

恢復內容開始 mysql常用命令 mysql建立資料表 語法 create table table name column name column type 建立乙個 student 表 1 create table student 2 stu id int notnull auto increme...