sqoop
舟率率 12/27/2023 sqoop
准备工作
CREATE TABLE IF NOT EXISTS test.t_user (
id BIGINT(22) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
username VARCHAR(128) NOT NULL COMMENT '用户名',
password VARCHAR(128) COMMENT '密码',
inserttime DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '插入时间',
updatetime DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
isactive TINYINT(1) NOT NULL DEFAULT '1' COMMENT '逻辑删除(1:保留,0:删除)',
PRIMARY KEY (id)
) ENGINE = InnoDB,
DEFAULT CHARSET = utf8mb4,
COLLATE = utf8mb4_unicode_ci,
COMMENT = '用户表';
insert into t_user (username,password) values('1','1');
insert into t_user (username,password) values('2','2');
insert into t_user (username,password) values('3','3');
insert into t_user (username,password) values('4','4');
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# sqoop 读取mysql 写入hdfs
sqoop import --username root --password 123456 --connect jdbc:mysql://master:3306/test --query 'select username,password from t_user where id>0 and $CONDITIONS' --target-dir /user/apophis/sqoop_data/ --delete-target-dir --fields-terminated-by ',' -m 1
1
# sqoop 抽取hdfs写mysql
sqoop export --connect jdbc:mysql://master:3306/test --username root --password 123456 --table t_user --columns username,password --export-dir /user/apophis/sqoop_data/part-m-00000 -m 1 --verbose --fields-terminated-by ','
1