sqoop sample code

來源:互聯網
上載者:User

標籤:

本文使用的資料庫是mysql的sample database employees.

download url:https://launchpad.net/test-db/employees-db-1/1.0.6

然後根據ReadMe安裝到自己的mysql資料庫中。

sqoop的安裝:

:http://apache.dataguru.cn/sqoop/1.4.6/

sqoop-1.4.6.bin__hadoop-2.0.4-alpha.tar.gz 
sqoop-1.4.6.tar.gz                 
我的hadoop版本是2.6,所以我下載的是這兩個版本。
sqoop-1.4.6.tar.gz不能直接使用,需要編譯。編譯後把產生的

sqoop-1.4.6.jar 複製到 sqoop_home/lib下面即可。

複製jdbc connector
mysql-connector-java-5.1.32-bin.jar 或版本更高的mysql jdbc connector.
否則會出現某些bug.
 
sqoop  list-tables --connect jdbc:mysql://namenode01:3306/employees --username hive --password hive   mysqlurl=jdbc:mysql://namenode01:3306/employees sqoop import --connect $mysqlurl --username hive --password hive --table departments --target-dir /etl/input/departments hdfs dfs -cat /etl/input/departments/* insert into departments values(‘d9999‘,‘Evan,Test‘);Overriding Type Mapping--map-column-java c1=Float,c2=String,c3=String ...Sqoop by default uses four concurrent map tasks to transfer data to Hadoop. mysqlurl=jdbc:mysql://namenode01:3306/employees sqoop import --connect $mysqlurl --username hive --password hive --query ‘select d.dept_no,d.dept_name,de.from_date, de.to_date, e.* from employees e join dept_emp de on e.emp_no=de.emp_no join departments d on de.dept_no=d.dept_no WHERE $CONDITIONS‘ --split-by d.dept_no --target-dir /etl/input/employees --compare the result count from mysql and hdfs filehdfs dfs -cat /etl/input/employees/* | wc -lif you want to overwrite the data type, you can specify the column=type--map-column-hive id=STRING,price=DECIMAL mysqlurl=jdbc:mysql://namenode01:3306/employees sqoop import --connect $mysqlurl --username hive --password hive --query ‘select d.dept_no,d.dept_name,de.from_date, de.to_date, e.* from employees e join dept_emp de on e.emp_no=de.emp_no join departments d on de.dept_no=d.dept_no WHERE $CONDITIONS‘ --split-by d.dept_no --hive-import --hive-table test.employees --hive-drop-import-delims --null-string ‘\\N‘ --null-non-string ‘\\N‘ --target-dir /tmp/employees

sqoop sample code

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.