[Sqoop]Sqoop匯入與匯出
阿新 • • 發佈:2019-01-19
1. 匯入例項
1.1 登陸資料庫查看錶
[email protected]:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.Commands end with ; or \g.
YourMySQL connection id is 8
Server version:5.6.30-0ubuntu0.15.10.1-log (Ubuntu)
Copyright(c)2000,2016,Oracle and/or its affiliates.All rights reserved.
Oracle is a registered trademark of
OracleCorporation and/or itsaffiliates.Other names may be trademarks of their respective
owners.
Type'help;' or '\h'for help.Type'\c' to clear the current input statement.
mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with
-ADatabase changed
mysql> show tables;
+-----------------+
|Tables_in_test|
+-----------------+
| employee |
| hotel_info |
+-----------------+
1.2 匯入操作
我們選擇employee這張表進行匯入。
匯入的命令非常簡單,如下:
mysql> select * from employee;
+--------+---------+-----------------+
| name | company | depart |
+--------+---------+-----------------+
| yoona | qunar |創新事業部|
| xiaosi | qunar |創新事業部|
| jim | ali |淘寶|
| kom | ali |淘寶|
sqoop import--connect jdbc:mysql://localhost:3306/test --table employee --username root -password root -m 1
上面程式碼是把test資料庫下employee表中資料匯入HDFS中,執行結果如下:
16/11/1316:37:35 INFO mapreduce.Job:The url to track the job: http://localhost:8080/
16/11/1316:37:35 INFO mapreduce.Job:Running job: job_local976138588_0001
16/11/1316:37:35 INFO mapred.LocalJobRunner:OutputCommitter set in config null
16/11/1316:37:35 INFO output.FileOutputCommitter:FileOutputCommitterAlgorithm version is 1
16/11/1316:37:35 INFO mapred.LocalJobRunner:OutputCommitter is org.apache.hadoop.mapreduce.lib.output.FileOutputCommitter
16/11/1316:37:35 INFO mapred.LocalJobRunner:Waitingfor map tasks
16/11/1316:37:35 INFO mapred.LocalJobRunner:Starting task: attempt_local976138588_0001_m_000000_0
16/11/1316:37:35 INFO output.FileOutputCommitter:FileOutputCommitterAlgorithm version is 1
16/11/1316:37:35 INFO mapred.Task:UsingResourceCalculatorProcessTree:[]
16/11/1316:37:35 INFO db.DBInputFormat:Using read commited transaction isolation
16/11/1316:37:35 INFO mapred.MapTask:Processing split:1=1 AND 1=1
16/11/1316:37:35 INFO db.DBRecordReader:Working on split:1=1 AND 1=1
16/11/1316:37:35 INFO db.DBRecordReader:Executing query: SELECT `name`,`company`,`depart` FROM `employee` AS `employee` WHERE (1=1) AND (1=1)
16/11/1316:37:35 INFO mapreduce.AutoProgressMapper:Auto-progress thread is finished. keepGoing=false
16/11/1316:37:35 INFO mapred.LocalJobRunner:
16/11/1316:37:35 INFO mapred.Task:Task:attempt_local976138588_0001_m_000000_0 is done.And is in the process of committing
16/11/1316:37:35 INFO mapred.LocalJobRunner:
16/11/1316:37:35 INFO mapred.Task:Task attempt_local976138588_0001_m_000000_0 is allowed to commit now
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
16/11/1316:37:35 INFO mapred.LocalJobRunner: map
16/11/1316:37:35 INFO mapred.Task:Task'attempt_local976138588_0001_m_000000_0' done.
16/11/1316:37:35 INFO mapred.LocalJobRunner:Finishing task: attempt_local976138588_0001_m_000000_0
16/11/1316:37:35 INFO mapred.LocalJobRunner: map task executor complete.
16/11/1316:37:36 INFO mapreduce.Job:Job job_local976138588_0001 running in uber mode :false
16/11/1316:37:36 INFO mapreduce.Job: map 100% reduce 0%
16/11/1316:37:36 INFO mapreduce.Job:Job job_local976138588_0001 completed successfully