1 분 소요

Sqoop

1. MySQL 서버 접속후 테이블 만들기

mysql -u root -phortonworks1
show databases;
use mysql;
show tables;
CREATE TABLE student
          (    _id INT PRIMARY KEY, 
               name VARCHAR(48) NOT NULL,
               belong VARCHAR(5),
               phone VARCHAR(11),
               status INT DEFAULT 0
          ) charset = utf8;
        
          INSERT INTO student VALUES
          (20090101, '루피', 'IDE', '01112345678', 1),
          (20100102, '조로', 'CSE', '01123435343', 4),
          (20110103, '상디', 'MSE', '01121342443', 1),
          (20100204, '버기', 'ESE', '01123424343', 2),
          (20110106, '프랑키', 'IME', '01134343222' , 0),
          (20080104, '나미', 'IDE', '01123432432', 6),
          (20090105, '쵸파', 'CSE', '01112342433', 8),
          (20090301, '에릭', 'ESE', '01132424244', 5),
          (20090302, '전진', 'IDE', '01112321313', 3),
          (20100505, '오공', 'CSE', '01123534644', 2),
          (20110506, '오천', 'MSE', '01121334525', 8),
          (20100507, '베지터', 'ESE', '01123423623', 0),
          (20110502, '부우', 'IME', '01134332634', 1),
          (20080501, '크리링', 'IDE', '01123436346', 2),
          (20090503, '피콜로', 'CSE', '01113634645', 3),
          (20090509, '셀', 'ESE', '01132427535', 0);

2.1. sqoop 을 이용해 테이블 리스트 조회 & table 정보를 hdfs에 저장

# 테이블 리스트
sqoop list-tables --connect jdbc:mysql://sandbox-hdp.hortonworks.com:3306/mysql --password hortonworks1 --username root

# 특정 table 정보를 hdfs에 저장
sqoop import --connect jdbc:mysql://sandbox-hdp.hortonworks.com:3306/mysql --password hortonworks1 --username root --table student --target-dir /user/hdfs/student --m 3 --where "_id < 20110000"

3. 빈 테이블 생성 후 sqoop export로 정보 삽입

CREATE TABLE student1
          (    _id INT PRIMARY KEY, 
               name VARCHAR(48) NOT NULL,
               belong VARCHAR(5),
               phone VARCHAR(11),
               status INT DEFAULT 0
          ) charset = utf8;
# sqoop으로 가져온 테이블 정보 SQL서버에 넣기

sqoop export --connect jdbc:mysql://sandbox-hdp.hortonworks.com:3306/mysql --password hortonworks1 --username root --table student1 --export-dir /user/hdfs/student

댓글남기기