$>!clear ; #清屏
$>!dfs -lsr / ; hive 執行dfs命令
$>show databases ; 檢視所有資料庫
okdefault
time taken: 1.693 seconds, fetched: 1 row(s)
我們發現只有乙個default庫;於是我們使用default 資料庫;
hive> use default ;
ok
time taken: 0.037 seconds
hive> create database dailiang ;
oktime taken: 0.076 seconds
hive> show databases ;
okdailiang
default
time taken: 0.016 seconds, fetched: 2 row(s)
刪除資料庫的時候,不允許刪除有資料的資料庫,如果資料庫裡面有資料則會報錯。如果要忽略這些內容,則在後面增加cascade關鍵字,則忽略報錯,刪除資料庫。
hive> drop database dailiang cascade ;
oktime taken: 0.11 seconds
直接檢視表資料:
hive> show tables in default ;
okismassetinfo
ismproinfo
ismsecuinfo
time taken: 0.017 seconds, fetched: 3 row(s)
或者直接使用
use 資料庫;
show tables ;
也可以使用正則表達數來看表資料
show tables like 'is*'
select * from ismproinfo ;
create table `dailiang_test`( name string , age int , *** string ,status string ) ;
hive> desc dailiang_test ;
okname string
age int
*** string
status string
time taken: 0.046 seconds, fetched: 4 row(s)
hive> show create table dailiang_test ;
okcreate table `dailiang_test`(
`name` string,
`age` int,
`***` string,
`status` string)
row format serde
'org.apache.hadoop.hive.serde2.lazy.lazy******serde'
stored as inputformat
'org.apache.hadoop.mapred.textinputformat'
outputformat
'org.apache.hadoop.hive.ql.io.hiveignorekeytextoutputformat'
location
'hdfs://ns-upid/user/hive/warehouse/dailiang.db/dailiang_test'
tblproperties (
'transient_lastddltime'='1501812307')
time taken: 0.046 seconds, fetched: 15 row(s)
hive> show create table ismproinfo ;
okcreate table `ismproinfo`(
`hash` string,
`innercode` string,
`secucode` string,
`ismcode` bigint,
`propabegindate` string,
`propaenddate` string,
`raisebegindate` string,
`raiseenddate` string,
`prorundate` string,
`prostopdate` string,
`maxstoresum` float,
`mininvestshare` float,
`acreturn` float,
`expreturn` float,
`levelrisk` smallint,
`createtime` string,
`status` smallint,
`slicecycle` smallint,
`risknum` float,
`classnum` smallint,
`stocknum` smallint,
`signum` smallint)
partitioned by (
`dt` string)
row format delimited
fields terminated by '|'
stored as inputformat
'org.apache.hadoop.mapred.textinputformat'
outputformat
'org.apache.hadoop.hive.ql.io.hiveignorekeytextoutputformat'
location
'hdfs://ns-upid/user/hive/warehouse/ismproinfo'
tblproperties (
'transient_lastddltime'='1476858329')
time taken: 0.209 seconds, fetched: 35 row(s)
匯出hive 資料到本地目錄
首先在本地建立目錄:
mkdir /hive_shuju
cd /hive_shuju
touch a.txt
echo 123 > a.txt
以下內容可以在hive中通過hive 的 shell命令進行檢視
hive> !ls /hive_shuju;
a.txt
hive> !cat /hive_shuju/a.txt;
123
匯出命令:(生產環境例子)
hive> insert overwrite local directory '/hive_shuju' select * from ismsecuinfo;
進入/hive_shuju目錄:
發現多了好多檔案:
000000_0 000002_0 000004_0 000006_0 000008_0 000010_0 000012_0 000014_0 000016_0 000018_0 000020_0
000001_0 000003_0 000005_0 000007_0 000009_0 000011_0 000013_0 000015_0 000017_0 000019_0
(ismsecuinfo 是個hive表,/hive_shuju 是linux 作業系統的乙個目錄)
注釋: 乙個或多個檔案會被寫入到/hive_shuju,具體個數取決於reducer的個數。不管在源表中資料實際是怎麼儲存的,hive會將所有的字段序列化成字串寫入到檔案中。
hive常見命令
hive常用命令 1 進入hive資料庫 hive 2 檢視hive中的所有資料庫 show databases 3 用default資料庫 use default 4 檢視所有的表 show tables 5 查詢表結構 desc mytest 表名 6 查詢表資料 select from myt...
Hive 常見設定
1.hive中 null 太多會占用大量空間 用這個可以減少占用 alter table test null set serdeproperties serialization.null.format 2.使用 sqoop 從mysql 和hive的 互相匯入 mysql 中 空 底層是用 null...
hive常見問題
distinct用法 對select 後面所有欄位去重,並不能只對一列去重 1 當distinct應用到多個欄位的時候,distinct必須放在開頭,其應用的範圍是其後面的所有字段,而不只是緊挨著它的乙個字段,而且distinct只能放到所有欄位的前面 2 distinct對null是不進行過濾的,...