Home  >  Article  >  Database  >  Alex的Hadoop菜鸟教程:第7课Sqoop2导出教程

Alex的Hadoop菜鸟教程:第7课Sqoop2导出教程

WBOY
WBOYOriginal
2016-06-07 16:10:561389browse

承接上节课,现在说说导出教程 检查连接 先看看有没有可用的connection 连接,如果没有就要根据上节课的方法创建一个 sqoop:000 show connector --all1 connector(s) to show: Connector with id 1: Name: generic-jdbc-connector Class: org.apache.sqoop.c

承接上节课,现在说说导出教程

检查连接

先看看有没有可用的connection 连接,如果没有就要根据上节课的方法创建一个

sqoop:000>  show connector --all
1 connector(s) to show: 
Connector with id 1:
  Name: generic-jdbc-connector 
 Class: org.apache.sqoop.connector.jdbc.GenericJdbcConnector
  Version: 1.99.3-cdh5.0.1
  Supported job types: [EXPORT, IMPORT]
    Connection form 1:


后面还有很长的输出我就不贴了,如果有就继续往下做

准备数据

mysql数据表准备

先在mysql 里面建立一个表 employee
CREATE TABLE `employee` (    
  `id` int(11) NOT NULL,    
  `name` varchar(20) NOT NULL,    
  PRIMARY KEY (`id`)    
) ENGINE=MyISAM  DEFAULT CHARSET=utf8; 

hadoop文件准备

在hadoop里面建立数据文件 先建立一个文件 part-m-00000 内容是
1,'michael'

把他们放到hadoop里面
# hdfs dfs -mkdir /user/alex
# hdfs dfs -put part-m-00000 /user/alex/
# hdfs dfs -ls /user/alex
Found 1 items
-rw-r--r--   2 root supergroup         20 2014-11-27 18:26 /user/alex/part-m-00000

导出

create job --xid 1 --type export

接下来按照提示输入

sqoop:000> create job --xid 1 --type export
Creating job for connection with id 1
Please fill following values to create new job object
Name: export to employee

Database configuration

Schema name: 
Table name: employee
Table SQL statement: 
Table column names: 
Stage table name: 
Clear stage table: 

Input configuration

Input directory: /user/alex

Throttling resources

Extractors: 
Loaders: 
New job was successfully created with validation status FINE  and persistent id 3

执行这个任务

sqoop:000> start job --jid 3
Submission details
Job ID: 3
Server URL: http://localhost:12000/sqoop/
Created by: root
Creation date: 2014-11-27 18:29:27 CST
Lastly updated by: root
External ID: job_1406097234796_0008
	http://xmseapp01:8088/proxy/application_1406097234796_0008/
2014-11-27 18:29:27 CST: BOOTING  - Progress is not available

然后等一会儿,再去看mysql的employee表就有一条michael 的记录了

下节课说下sqoop跟Hbase之间的通讯



后面还有很长的输出我就不贴了,如果有就继续往下做
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn