hive、sqoop、MySQL間的資料傳遞

來源:互聯網
上載者:User

標籤:import   cat   使用者訪問   war   傳遞   載入   div   特點   append   

hdfs到MySQL

csv/txt檔案到hdfs

MySQL到hdfs

 hive與hdfs的映射:

drop table if exists emp;
create table emp( id int comment ‘ID‘, emp_name string comment ‘姓名‘, job string ) comment ‘職業‘ row format delimited -- stored as rcfile location ‘/user/hive/warehouse/emp‘;

stored as 關鍵詞,hive目前支援三種方式:
1:就是最普通的textfile,資料不做壓縮,磁碟開銷大,解析開銷也大
2:SquenceFIle,hadoop api提供的一種二進位API方式,其具有使用方便、可分割、可壓縮等特點。
3:rcfile行列儲存結合的方式,它會首先將資料進行分塊,保證同一個record在一個分塊上,避免讀一次記錄需要讀多個塊。其次塊資料列式儲存,便於資料存放區和快速的列存取。
RCFILE由於採用是的列式儲存,所以載入時候開銷較大,但具有很好的查詢響應、較好的壓縮比。
如果建立的表需要加上分區,則語句如下:
這裡partitioned by 表示按什麼欄位進行分割,通常來說是按時間

 

Hadoop指令查看hdfs下的資料

 

將本機資料檔案匯入到hdfs下面:

比較利用Hadoop指令將資料上傳至hdfs路徑

create external table if not exists emp(id int comment ‘使用者名稱‘,name string comment ‘月份‘,job string comment ‘訪問次數‘) comment ‘使用者訪問表‘ row format delimited fields terminated by "\t" location "/user/hive/warehouse/test.db";
-- 方法1. 將檔案直接上傳至hdfshadoop dfs -put /root/part-m-00000 /user/hive/warehouse/test.db
-- 方法2. 通過hive 的 load方法將資料傳至hdfsload data local inpath "/root/part-m-00000" into table test.emp;

以上兩種方法實現的效果相同;注意一點就是 資料間的 間隔符號  “\t”

方法3. 利用sqoop將資料傳至hdfs  <sqoop是MySQL與hdfs之間資料傳遞工具>

sqoop import --connect jdbc:mysql://192.168.5.129:3306/hadoop --username root --password 111111 --table emp_demo --fields-terminated-by ‘\t‘ -m 1 --target-dir /user/hive/warehouse/test.db
 sqoop import --connect jdbc:mysql://localhost:3306/test --username root --password 123456 --table person --append --target-dir /user/hive/warehouse/test.db

將hdfs資料儲存到MySQL

 sqoop export --connect jdbc:mysql://localhost/db --username root --table employee --export-dir /emp/emp_data

 

hive、sqoop、MySQL間的資料傳遞

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.