Sqoop将MySQL的表数据同步到HDFS(一)

系统环境

操作系统: CentOS 7
主机名:   centos02
IP:      192.168.122.1
Java:    1.8
Hadoop:  2.8.5
Sqoop: 1.4.7
MySQL: 8.0.12

 

一、脚本 (以逗号为分隔符) 

sqoop import 
--connect jdbc:mysql://centos02:3306/OfficialCashMid 
--driver com.mysql.cj.jdbc.Driver 
--username root 
--password sa123_ADMIN. 
--table tadminoperationlog 
--m 2 
--target-dir /jdbcHDFS/TAdminLog_txt2 
--fields-terminated-by ','  

先启动 Hadoop

[root@centos02 centos02]# cd $HADOOP_HOME/sbin
[root@centos02 sbin]# start-all.sh
[root@centos02 sbin]#
[root@centos02 sbin]# jps
5443 ResourceManager
5269 SecondaryNameNode
5062 DataNode
5752 NodeManager
6202 Jps
4907 NameNode
[root@centos02 sbin]#
[root@centos02 sbin]# cd $SQOOP_HOME/bin
[root@centos02 bin]# sqoop import --connect jdbc:mysql://centos02:3306/OfficialCashMid --driver com.mysql.cj.jdbc.Driver --username root --password sa123_ADMIN. --table tadminoperationlog --m 2 --target-dir /jdbcHDFS/TAdminLog_txt2 --fields-terminated-by ',' 
Warning: /opt/bigdata/sqoop/sqoop-1.4.7/../hbase does not exist! HBase imports will fail.
Please set $HBASE_HOME to the root of your HBase installation.
Warning: /opt/bigdata/sqoop/sqoop-1.4.7/../hcatalog does not exist! HCatalog jobs will fail.
Please set $HCAT_HOME to the root of your HCatalog installation.
Warning: /opt/bigdata/sqoop/sqoop-1.4.7/../accumulo does not exist! Accumulo imports will fail.
Please set $ACCUMULO_HOME to the root of your Accumulo installation.
Warning: /opt/bigdata/sqoop/sqoop-1.4.7/../zookeeper does not exist! Accumulo imports will fail.
Please set $ZOOKEEPER_HOME to the root of your Zookeeper installation.
19/09/04 00:34:44 INFO sqoop.Sqoop: Running Sqoop version: 1.4.7
19/09/04 00:34:45 WARN tool.BaseSqoopTool: Setting your password on the command-line is insecure. Consider using -P instead.
19/09/04 00:34:45 WARN sqoop.ConnFactory: Parameter --driver is set to an explicit driver however appropriate connection manager is not being set (via --connection-manager). Sqoop is going to fall back to org.apache.sqoop.manager.GenericJdbcManager. Please specify explicitly which connection manager should be used next time.
19/09/04 00:34:45 INFO manager.SqlManager: Using default fetchSize of 1000
19/09/04 00:34:45 INFO tool.CodeGenTool: Beginning code generation
19/09/04 00:34:47 INFO manager.SqlManager: Executing SQL statement: SELECT t.* FROM tadminoperationlog AS t WHERE 1=0
19/09/04 00:34:47 INFO manager.SqlManager: Executing SQL statement: SELECT t.* FROM tadminoperationlog AS t WHERE 1=0
19/09/04 00:34:47 INFO orm.CompilationManager: HADOOP_MAPRED_HOME is /opt/bigdata/hadoop/hadoop-2.8.5
注: /tmp/sqoop-root/compile/8d4f36a54db73bbda22a70d5cd8b668e/tadminoperationlog.java使用或覆盖了已过时的 API。
注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。
19/09/04 00:36:22 INFO orm.CompilationManager: Writing jar file: /tmp/sqoop-root/compile/8d4f36a54db73bbda22a70d5cd8b668e/tadminoperationlog.jar
19/09/04 00:36:26 INFO mapreduce.ImportJobBase: Beginning import of tadminoperationlog
19/09/04 00:36:31 INFO Configuration.deprecation: mapred.jar is deprecated. Instead, use mapreduce.job.jar
19/09/04 00:36:31 INFO manager.SqlManager: Executing SQL statement: SELECT t.* FROM tadminoperationlog AS t WHERE 1=0
19/09/04 00:37:23 INFO Configuration.deprecation: mapred.map.tasks is deprecated. Instead, use mapreduce.job.maps
19/09/04 00:37:23 INFO client.RMProxy: Connecting to ResourceManager at centos02/192.168.122.1:8032
19/09/04 00:38:07 INFO db.DBInputFormat: Using read commited transaction isolation
19/09/04 00:38:07 INFO db.DataDrivenDBInputFormat: BoundingValsQuery: SELECT MIN(FID), MAX(FID) FROM tadminoperationlog
19/09/04 00:38:07 INFO db.IntegerSplitter: Split size: 16058; Num splits: 2 from: 21 to: 32138
19/09/04 00:38:08 INFO mapreduce.JobSubmitter: number of splits:2
19/09/04 00:38:08 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_1567503661837_0001
19/09/04 00:38:27 INFO impl.YarnClientImpl: Submitted application application_1567503661837_0001
19/09/04 00:38:27 INFO mapreduce.Job: The url to track the job: http://centos02:8088/proxy/application_1567503661837_0001/
19/09/04 00:38:27 INFO mapreduce.Job: Running job: job_1567503661837_0001
19/09/04 00:40:54 INFO mapreduce.Job: Job job_1567503661837_0001 running in uber mode : false
19/09/04 00:40:54 INFO mapreduce.Job:  map 0% reduce 0%
19/09/04 00:43:32 INFO mapreduce.Job:  map 100% reduce 0%
19/09/04 00:43:35 INFO mapreduce.Job: Job job_1567503661837_0001 completed successfully
19/09/04 00:43:35 INFO mapreduce.Job: Counters: 30
    File System Counters
        FILE: Number of bytes read=0
        FILE: Number of bytes written=357730
        FILE: Number of read operations=0
        FILE: Number of large read operations=0
        FILE: Number of write operations=0
        HDFS: Number of bytes read=206
        HDFS: Number of bytes written=3753700
        HDFS: Number of read operations=8
        HDFS: Number of large read operations=0
        HDFS: Number of write operations=4
    Job Counters 
        Launched map tasks=2
        Other local map tasks=2
        Total time spent by all maps in occupied slots (ms)=308882
        Total time spent by all reduces in occupied slots (ms)=0
        Total time spent by all map tasks (ms)=308882
        Total vcore-milliseconds taken by all map tasks=308882
        Total megabyte-milliseconds taken by all map tasks=316295168
    Map-Reduce Framework
        Map input records=12122
        Map output records=12122
        Input split bytes=206
        Spilled Records=0
        Failed Shuffles=0
        Merged Map outputs=0
        GC time elapsed (ms)=1178
        CPU time spent (ms)=18360
        Physical memory (bytes) snapshot=362246144
        Virtual memory (bytes) snapshot=4272762880
        Total committed heap usage (bytes)=183500800
    File Input Format Counters 
        Bytes Read=0
    File Output Format Counters 
        Bytes Written=3753700
19/09/04 00:43:35 INFO mapreduce.ImportJobBase: Transferred 3.5798 MB in 372.5102 seconds (9.8406 KB/sec)
19/09/04 00:43:35 INFO mapreduce.ImportJobBase: Retrieved 12122 records.
[root@centos02 bin]# 

 

二、脚本 (以\t为分隔符,默认的存储格式是textfile) 

sqoop import 
--connect jdbc:mysql://centos02:3306/OfficialCashMid 
--driver com.mysql.cj.jdbc.Driver 
--username root 
--password sa123_ADMIN. 
--table tadminoperationlog 
--m 2 
--target-dir /jdbcHDFS/TAdminLog_txt 
--fields-terminated-by '\t' 
[root@centos02 bin]# sqoop import --connect jdbc:mysql://centos02:3306/OfficialCashMid --driver com.mysql.cj.jdbc.Driver --username root --password sa123_ADMIN. --table tadminoperationlog --m 2 --target-dir /jdbcHDFS/TAdminLog_txt --fields-terminated-by '\t' 
Warning: /opt/bigdata/sqoop/sqoop-1.4.7/../hbase does not exist! HBase imports will fail.
Please set $HBASE_HOME to the root of your HBase installation.
Warning: /opt/bigdata/sqoop/sqoop-1.4.7/../hcatalog does not exist! HCatalog jobs will fail.
Please set $HCAT_HOME to the root of your HCatalog installation.
Warning: /opt/bigdata/sqoop/sqoop-1.4.7/../accumulo does not exist! Accumulo imports will fail.
Please set $ACCUMULO_HOME to the root of your Accumulo installation.
Warning: /opt/bigdata/sqoop/sqoop-1.4.7/../zookeeper does not exist! Accumulo imports will fail.
Please set $ZOOKEEPER_HOME to the root of your Zookeeper installation.
19/09/04 00:48:38 INFO sqoop.Sqoop: Running Sqoop version: 1.4.7
19/09/04 00:48:38 WARN tool.BaseSqoopTool: Setting your password on the command-line is insecure. Consider using -P instead.
19/09/04 00:48:38 WARN sqoop.ConnFactory: Parameter --driver is set to an explicit driver however appropriate connection manager is not being set (via --connection-manager). Sqoop is going to fall back to org.apache.sqoop.manager.GenericJdbcManager. Please specify explicitly which connection manager should be used next time.
19/09/04 00:48:38 INFO manager.SqlManager: Using default fetchSize of 1000
19/09/04 00:48:38 INFO tool.CodeGenTool: Beginning code generation
19/09/04 00:48:40 INFO manager.SqlManager: Executing SQL statement: SELECT t.* FROM tadminoperationlog AS t WHERE 1=0
19/09/04 00:48:40 INFO manager.SqlManager: Executing SQL statement: SELECT t.* FROM tadminoperationlog AS t WHERE 1=0
19/09/04 00:48:40 INFO orm.CompilationManager: HADOOP_MAPRED_HOME is /opt/bigdata/hadoop/hadoop-2.8.5
注: /tmp/sqoop-root/compile/8a3e18040bc4b3be92c902169935cc82/tadminoperationlog.java使用或覆盖了已过时的 API。
注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。
19/09/04 00:48:53 INFO orm.CompilationManager: Writing jar file: /tmp/sqoop-root/compile/8a3e18040bc4b3be92c902169935cc82/tadminoperationlog.jar
19/09/04 00:48:54 INFO mapreduce.ImportJobBase: Beginning import of tadminoperationlog
19/09/04 00:48:54 INFO Configuration.deprecation: mapred.jar is deprecated. Instead, use mapreduce.job.jar
19/09/04 00:48:54 INFO manager.SqlManager: Executing SQL statement: SELECT t.* FROM tadminoperationlog AS t WHERE 1=0
19/09/04 00:48:55 INFO Configuration.deprecation: mapred.map.tasks is deprecated. Instead, use mapreduce.job.maps
19/09/04 00:48:55 INFO client.RMProxy: Connecting to ResourceManager at centos02/192.168.122.1:8032
19/09/04 00:49:03 INFO db.DBInputFormat: Using read commited transaction isolation
19/09/04 00:49:03 INFO db.DataDrivenDBInputFormat: BoundingValsQuery: SELECT MIN(FID), MAX(FID) FROM tadminoperationlog
19/09/04 00:49:03 INFO db.IntegerSplitter: Split size: 16058; Num splits: 2 from: 21 to: 32138
19/09/04 00:49:04 INFO mapreduce.JobSubmitter: number of splits:2
19/09/04 00:49:05 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_1567503661837_0002
19/09/04 00:49:05 INFO impl.YarnClientImpl: Submitted application application_1567503661837_0002
19/09/04 00:49:05 INFO mapreduce.Job: The url to track the job: http://centos02:8088/proxy/application_1567503661837_0002/
19/09/04 00:49:05 INFO mapreduce.Job: Running job: job_1567503661837_0002
19/09/04 00:49:18 INFO mapreduce.Job: Job job_1567503661837_0002 running in uber mode : false
19/09/04 00:49:18 INFO mapreduce.Job:  map 0% reduce 0%
19/09/04 00:50:16 INFO mapreduce.Job:  map 100% reduce 0%
19/09/04 00:50:27 INFO mapreduce.Job: Job job_1567503661837_0002 completed successfully
19/09/04 00:50:27 INFO mapreduce.Job: Counters: 30
    File System Counters
        FILE: Number of bytes read=0
        FILE: Number of bytes written=357728
        FILE: Number of read operations=0
        FILE: Number of large read operations=0
        FILE: Number of write operations=0
        HDFS: Number of bytes read=206
        HDFS: Number of bytes written=3753700
        HDFS: Number of read operations=8
        HDFS: Number of large read operations=0
        HDFS: Number of write operations=4
    Job Counters 
        Launched map tasks=2
        Other local map tasks=2
        Total time spent by all maps in occupied slots (ms)=120209
        Total time spent by all reduces in occupied slots (ms)=0
        Total time spent by all map tasks (ms)=120209
        Total vcore-milliseconds taken by all map tasks=120209
        Total megabyte-milliseconds taken by all map tasks=123094016
    Map-Reduce Framework
        Map input records=12122
        Map output records=12122
        Input split bytes=206
        Spilled Records=0
        Failed Shuffles=0
        Merged Map outputs=0
        GC time elapsed (ms)=2068
        CPU time spent (ms)=18450
        Physical memory (bytes) snapshot=380551168
        Virtual memory (bytes) snapshot=4272668672
        Total committed heap usage (bytes)=175112192
    File Input Format Counters 
        Bytes Read=0
    File Output Format Counters 
        Bytes Written=3753700
19/09/04 00:50:27 INFO mapreduce.ImportJobBase: Transferred 3.5798 MB in 91.9218 seconds (39.8787 KB/sec)
19/09/04 00:50:27 INFO mapreduce.ImportJobBase: Retrieved 12122 records.
[root@centos02 bin]# 

 

posted @ 2019-09-05 00:11  茗::流  阅读(811)  评论(0)    收藏  举报
如有雷同,纯属参考。如有侵犯你的版权,请联系我。