标签:list 行数据 reader engine hdf alt 逗号 use user
sqoop help
sqoop list-databases --connect jdbc:mysql://hadoop02:3306/ --username root --password 123456
sqoop list-tables --connect jdbc:mysql://hadoop02:3306/mysql --username root --password 123456
在mysql中有一个库userdb中三个表:emp, emp_add和emp_conn
表emp:
id | name | deg | salary | dept |
---|---|---|---|---|
1201 | gopal | manager | 50,000 | TP |
1202 | manisha | Proof reader | 50,000 | TP |
1203 | khalil | php dev | 30,000 | AC |
1204 | prasanth | php dev | 30,000 | AC |
1205 | kranthi | admin | 20,000 | TP |
表emp_add:
id | hno | street | city |
---|---|---|---|
1201 | 288A | vgiri | jublee |
1202 | 108I | aoc | sec-bad |
1203 | 144Z | pgutta | hyd |
1204 | 78B | old city | sec-bad |
1205 | 720X | hitec | sec-bad |
表emp_conn:
id | phno | |
---|---|---|
1201 | 2356742 | gopal@tp.com |
1202 | 1661663 | manisha@tp.com |
1203 | 8887776 | khalil@ac.com |
1204 | 9988774 | prasanth@ac.com |
1205 | 1231231 | kranthi@tp.com |
建表语句如下:
CREATE DATABASE /*!32312 IF NOT EXISTS*/`userdb` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `userdb`;
DROP TABLE IF EXISTS `emp`;
CREATE TABLE `emp` (
`id` INT(11) DEFAULT NULL,
`name` VARCHAR(100) DEFAULT NULL,
`deg` VARCHAR(100) DEFAULT NULL,
`salary` INT(11) DEFAULT NULL,
`dept` VARCHAR(10) DEFAULT NULL,
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`is_delete` BIGINT(20) DEFAULT ‘1‘
) ENGINE=INNODB DEFAULT CHARSET=latin1;
INSERT INTO `emp`(`id`,`name`,`deg`,`salary`,`dept`) VALUES (1201,‘gopal‘,‘manager‘,50000,‘TP‘),(1202,‘manisha‘,‘Proof reader‘,50000,‘TP‘),(1203,‘khalil‘,‘php dev‘,30000,‘AC‘),(1204,‘prasanth‘,‘php dev‘,30000,‘AC‘),(1205,‘kranthi‘,‘admin‘,20000,‘TP‘);
DROP TABLE IF EXISTS `emp_add`;
CREATE TABLE `emp_add` (
`id` INT(11) DEFAULT NULL,
`hno` VARCHAR(100) DEFAULT NULL,
`street` VARCHAR(100) DEFAULT NULL,
`city` VARCHAR(100) DEFAULT NULL,
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`is_delete` BIGINT(20) DEFAULT ‘1‘
) ENGINE=INNODB DEFAULT CHARSET=latin1;
INSERT INTO `emp_add`(`id`,`hno`,`street`,`city`) VALUES (1201,‘288A‘,‘vgiri‘,‘jublee‘),(1202,‘108I‘,‘aoc‘,‘sec-bad‘),(1203,‘144Z‘,‘pgutta‘,‘hyd‘),(1204,‘78B‘,‘old city‘,‘sec-bad‘),(1205,‘720X‘,‘hitec‘,‘sec-bad‘);
DROP TABLE IF EXISTS `emp_conn`;
CREATE TABLE `emp_conn` (
`id` INT(100) DEFAULT NULL,
`phno` VARCHAR(100) DEFAULT NULL,
`email` VARCHAR(100) DEFAULT NULL,
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`is_delete` BIGINT(20) DEFAULT ‘1‘
) ENGINE=INNODB DEFAULT CHARSET=latin1;
INSERT INTO `emp_conn`(`id`,`phno`,`email`) VALUES (1201,‘2356742‘,‘gopal@tp.com‘),(1202,‘1661663‘,‘manisha@tp.com‘),(1203,‘8887776‘,‘khalil@ac.com‘),(1204,‘9988774‘,‘prasanth@ac.com‘),(1205,‘1231231‘,‘kranthi@tp.com‘);
sqoop import --connect jdbc:mysql://hadoop02:3306/userdb --password 123456 --username root --table emp -m 1
如果成功执行,那么会得到下面的输出。
为了验证在HDFS导入的数据,请使用以下命令查看导入的数据
hdfs dfs -ls /user/hadoop/emp
--m 1
,表示只启动一个map task进行数据的导入--split-by column-name
,如下,其中map个数为4sqoop import --connect jdbc:mysql://hadoop02:3306/userdb --password 123456 --username root --table emp -m 4 --split-by id
sqoop import --connect jdbc:mysql://hadoop02:3306/userdb --username root --password 123456 --delete-target-dir --table emp --target-dir /sqoop/emp -m 1
hdfs dfs -text /sqoop/emp/part-m-00000
1201,gopal,manager,50000,TP
1202,manisha,Proof reader,50000,TP
1203,khalil,php dev,30000,AC
1204,prasanth,php dev,30000,AC
1205,kranthi,admin,20000,TP
sqoop import --connect jdbc:mysql://hadoop02:3306/userdb --username root --password 123456 --delete-target-dir --table emp --target-dir /sqoop/emp2 -m 1 --fields-terminated-by ‘\t‘
hdfs dfs -text /sqoop/emp2/part-m-00000
标签:list 行数据 reader engine hdf alt 逗号 use user
原文地址:https://www.cnblogs.com/tenic/p/14897834.html