sqoop(4):export之hdfsTomysql

1.直接命令提交

(1)在mysql的sqoop下创建tomysql这张表

create table tomysql(
id int primary key not null,
name varchar(20) not null
);

(2)命令行

bin/sqoop export \
--connect jdbc:mysql://bigdata.ibeifeng.com:3306/sqoop \
--username root \
--password 123456 \
--table tomysql \
--export-dir /sqoop \
--num-mappers 1 \
--input-fields-terminated-by '\t'

mysql结果:
+----+----------+
| id | name     |
+----+----------+
|  1 | jack     |
|  2 | leo      |
|  3 | peter    |
|  4 | tom      |
|  5 | linda    |
|  6 | marry    |
|  7 | jerry    |
|  8 | zhangsan |
|  9 | lisi     |

2、使用sqoop运行一个file文件:--options-file

(1)先在mysql中创建一张表

create table filetomysql(
id int primary key not null,
name varchar(20) not null
);

(2)然后创建文本vi sqoop.file写命令

    写法:一行是key,下一行是value

    备注:--export-dir时hdfs需要输出的目录

export
--connect
jdbc:mysql://bigdata.ibeifeng.com:3306/sqoop
--username
root
--password
123456
--table
filetomysql
--export-dir
/sqoop
-m
1
--input-fields-terminated-by
'\t'

(3)执行

bin/sqoop --options-file sqoop.file

猜你喜欢

转载自blog.csdn.net/u010886217/article/details/83954606