sqoop实现数据迁移

    技术2022-07-13  71

    sqoop命令中的 \ 后不能接任何空格,否则报错

    (1)sqoop help 查看命令 (2)显示所有库名 方式一: sqoop list-databases –connect jdbc:mysql://...:3306 –username root –password 123456

    方式二: sqoop list-databases –connect jdbc:mysql://...:3306 –username root -P

    后直接提示通过键盘输入数据库密码

    (3)显示某个数据库里所有表 sqoop list-tables –connect jdbc:mysql://.2..:3*/sqoop –username root –password 123456

    (4)MYSQL导入数据到HIVE

    sqoop import “-Dorg.apache.sqoop.splitter.allow_text_splitter=true” –connect jdbc:mysql://172.2.10.93:3306/sqoop –split-by id –username root –password 123456 –table customer –hive-import –create-hive-table –fields-terminated-by “\t” -m 5

    参数说明: “-Dorg.apache.sqoop.splitter.allow_text_splitter=true” 表示文本 –split-by 表示分隔列,如果有主键的话,可不进行设置 –table表示 mysql数据库中的表 –hive-import 是必须参数,指定导入hive –create-hive-table 表示在default数据库中新建与mysql数据库中相同名称的表 –hive-import 必须参数,指定导入hive

    –hive-database default hive库名 –hive-table people hive表名 –fields-terminated-by hive的分隔符 –hive-overwrite 重写重复字段 –create-hive-table 帮创建好 hive 表,但是表存在会出错。不建议使用这个参数,因为到导入的时候,会与我们的字段类型有出入。 –hive-partition-key “dt” 指定分区表的字段 –hive-partition-value “2018-08-08” 指定分区表的值

    例如: sqoop import –connect jdbc:mysql://...:3306/sqoop –username root –password 123456 –table stu –hive-import –create-hive-table –fields-terminated-by “\t” -m 5

    导入第一天数据 ./sqoop import –connect jdbc:mysql://...:3306/populcationcensus –username root –password 123456 –split-by id –table A1 –hive-import –hive-database default –hive-table AntiepidemicData –fields-terminated-by “\t” -m 5

    导入第二天数据 ./sqoop import –connect jdbc:mysql://...:3306/populcationcensus –username root –password 123456 –split-by id –table A2 –hive-import –incremental append –check-column id –hive-database default –hive-table A –fields-terminated-by “\t” -m 5

    导入第三天数据 ./sqoop import –connect jdbc:mysql://...:3306/populcationcensus –username root –password 123456 –split-by id –table A3 –hive-import –incremental append –check-column id –hive-database default –hive-table A –fields-terminated-by “\t” -m 5

    导入到hive的具体分区中

    Processed: 0.016, SQL: 9