1. 程式人生 > >[Sqoop]Sqoop匯入與匯出

[Sqoop]Sqoop匯入與匯出

1. 匯入例項
1.1 登陸資料庫查看錶
  1. [email protected]:~$ mysql -u root -p
  2. Enter password:
  3. Welcome to the MySQL monitor.Commands end with ; or \g.
  4. YourMySQL connection id is 8
  5. Server version:5.6.30-0ubuntu0.15.10.1-log (Ubuntu)
  6. Copyright(c)2000,2016,Oracle and/or its affiliates.All rights reserved.
  7. Oracle is a registered trademark of
    OracleCorporation and/or its
  8. affiliates.Other names may be trademarks of their respective
  9. owners.
  10. Type'help;' or '\h'for help.Type'\c' to clear the current input statement.
  11. mysql> use test;
  12. Reading table information for completion of table and column names
  13. You can turn off this feature to get a quicker startup with
    -A
  14. Database changed
  15. mysql> show tables;
  16. +-----------------+
  17. |Tables_in_test|
  18. +-----------------+
  19. | employee        |
  20. | hotel_info      |
  21. +-----------------+
1.2 匯入操作

我們選擇employee這張表進行匯入。

  1. mysql> select * from employee;
  2. +--------+---------+-----------------+
  3. | name | company | depart |
  4. +--------+---------+-----------------+
  5. | yoona | qunar |創新事業部|
  6. | xiaosi | qunar |創新事業部|
  7. | jim | ali |淘寶|
  8. | kom | ali |淘寶|
匯入的命令非常簡單,如下:
  1. sqoop import--connect jdbc:mysql://localhost:3306/test --table employee --username root -password root -m 1

上面程式碼是把test資料庫下employee表中資料匯入HDFS中,執行結果如下:

  1. 16/11/1316:37:35 INFO mapreduce.Job:The url to track the job: http://localhost:8080/
  2. 16/11/1316:37:35 INFO mapreduce.Job:Running job: job_local976138588_0001
  3. 16/11/1316:37:35 INFO mapred.LocalJobRunner:OutputCommitter set in config null
  4. 16/11/1316:37:35 INFO output.FileOutputCommitter:FileOutputCommitterAlgorithm version is 1
  5. 16/11/1316:37:35 INFO mapred.LocalJobRunner:OutputCommitter is org.apache.hadoop.mapreduce.lib.output.FileOutputCommitter
  6. 16/11/1316:37:35 INFO mapred.LocalJobRunner:Waitingfor map tasks
  7. 16/11/1316:37:35 INFO mapred.LocalJobRunner:Starting task: attempt_local976138588_0001_m_000000_0
  8. 16/11/1316:37:35 INFO output.FileOutputCommitter:FileOutputCommitterAlgorithm version is 1
  9. 16/11/1316:37:35 INFO mapred.Task:UsingResourceCalculatorProcessTree:[]
  10. 16/11/1316:37:35 INFO db.DBInputFormat:Using read commited transaction isolation
  11. 16/11/1316:37:35 INFO mapred.MapTask:Processing split:1=1 AND 1=1
  12. 16/11/1316:37:35 INFO db.DBRecordReader:Working on split:1=1 AND 1=1
  13. 16/11/1316:37:35 INFO db.DBRecordReader:Executing query: SELECT `name`,`company`,`depart` FROM `employee` AS `employee` WHERE (1=1) AND (1=1)
  14. 16/11/1316:37:35 INFO mapreduce.AutoProgressMapper:Auto-progress thread is finished. keepGoing=false
  15. 16/11/1316:37:35 INFO mapred.LocalJobRunner:
  16. 16/11/1316:37:35 INFO mapred.Task:Task:attempt_local976138588_0001_m_000000_0 is done.And is in the process of committing
  17. 16/11/1316:37:35 INFO mapred.LocalJobRunner:
  18. 16/11/1316:37:35 INFO mapred.Task:Task attempt_local976138588_0001_m_000000_0 is allowed to commit now
  19. 16/11/1316:37:35 INFO output.FileOutputCommitter:Saved output of task 'attempt_local976138588_0001_m_000000_0' to hdfs://localhost:9000/user/xiaosi/employee/_temporary/0/task_local976138588_0001_m_000000
  20. 16/11/1316:37:35 INFO mapred.LocalJobRunner: map
  21. 16/11/1316:37:35 INFO mapred.Task:Task'attempt_local976138588_0001_m_000000_0' done.
  22. 16/11/1316:37:35 INFO mapred.LocalJobRunner:Finishing task: attempt_local976138588_0001_m_000000_0
  23. 16/11/1316:37:35 INFO mapred.LocalJobRunner: map task executor complete.
  24. 16/11/1316:37:36 INFO mapreduce.Job:Job job_local976138588_0001 running in uber mode :false
  25. 16/11/1316:37:36 INFO mapreduce.Job: map 100% reduce 0%
  26. 16/11/1316:37:36 INFO mapreduce.Job:Job job_local976138588_0001 completed successfully