利用以下命令可以檢視hive中的資料庫和**。
show databases; #檢視資料庫
show tables; #檢視**
(一)將本地/home/training/student.csv**匯入到hive中
1.在hive中建立新**,與本地csv的資料型別一致
create
table
ifnot
exists student1
(id int, age int, *** string, birthday date, score int)
row format delimited fields terminated by
','stored as textfile;
2.檢視新建的**
describe student1;
describe formatted student1;
3.匯入本地資料
load data local inpath '/home/training/student.csv' overwrite into
table student1;
set hive.cli.print.header=true; #顯示列名
bingo,匯入本地資料成功!
(二)將hdfs端的/test/student.csv**匯入到hive中
hdfs dfs -mkdir /test #新建資料夾
hdfs dfs -put /home/training/student.csv /test #上傳本地student.csv到hdfs端的test資料夾下
bingo,匯入hdfs端資料成功!
(二)將mysql中的**匯入到hive中
如果hive的metastore資料庫不是mysql的話,可以利用sqoop先將mysql資料庫中的表匯入hdfs端,再把hdfs端的資料匯入到hive中。
下面僅展示如何利用sqoop先將mysql資料庫中test資料庫的student_mysql表匯入hdfs端。
sqoop import \
--connect jdbc:
mysql://localhost/test \
--username training --password training \
--table student_mysql \
--target-dir /lmj/student_hdfs \
--null-non-string '\\n';
其中,import為sqoop內建的匯入單張表的命令,jdbc:mysql://localhost/test為本地mysql的test資料庫,username和password分別為mysql資料庫的賬號與密碼,table student_mysql為所要匯入的表,target-dir為hdfs端的檔案位址,null-non-string 『\n』將資料庫表中的null值轉化為hive和impala中的\n,便於相容。 hive建立外部表,匯入資料
在hdfs建立分割槽,並存有檔案 手工建立或者由程式在hdfs上生成了分割槽目錄,每個分割槽目錄下有相應的檔案。vi test.txt 2 lily 1991 shanghai 3 jack 1992 guangxi 4 jenny 1999 xinjiang 5 jay 1995 xizang 6...
Hive內部表與外部表,資料匯入,資料匯出
1,內部表資料由hive自身管理,外部表資料由hdfs管理 2,刪除內部表會直接刪除元資料 metadata 及儲存資料 刪除外部表僅僅會刪除元資料,hdfs上的檔案並不會被刪除 3,內部表資料儲存的位置是hive.metastore.warehouse.dir 預設 user hive wareh...
hive之insert匯入分割槽資料
資料庫分割槽的主要目的是為了在特定的sql操作中減少資料讀寫的總量以縮減響應時間,主要包括兩種分割槽形式 水平分割槽與垂直分割槽。水平分割槽是對錶進行行分割槽。而垂直分割槽是對列進行分割槽,一般是通過對錶的垂直劃分來減少目標表的寬度,常用的是水平分割槽。回到頂部 hive.exec.max.dyna...