2023-06-06 18:10:33,041 INFO sqoop.Sqoop: Running Sqoop version: 1.4.7 2023-06-06 18:10:33,075 WARN tool.BaseSqoopTool: Setting your password on the command-line is insecure. Consider using -P instead. 2023-06-06 18:10:33,218 INFO manager.MySQLManager: Preparing to use a MySQL streaming resultset. 2023-06-06 18:10:33,218 INFO tool.CodeGenTool: Beginning code generation Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary. 2023-06-06 18:10:33,782 INFO manager.SqlManager: Executing SQL statement: SELECT t.* FROM `user_log` AS t LIMIT 1 2023-06-06 18:10:33,825 INFO manager.SqlManager: Executing SQL statement: SELECT t.* FROM `user_log` AS t LIMIT 1 2023-06-06 18:10:33,834 INFO orm.CompilationManager: HADOOP_MAPRED_HOME is /opt/module/hadoop-3.1.4 注: /tmp/sqoop-root/compile/5f4cfb16d119de74d33f1a0d776d5ae0/user_log.java使用或覆盖了已过时的 API。 注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。 2023-06-06 18:10:35,111 INFO orm.CompilationManager: Writing jar file: /tmp/sqoop-root/compile/5f4cfb16d119de74d33f1a0d776d5ae0/user_log.jar 2023-06-06 18:10:35,125 WARN manager.MySQLManager: It looks like you are importing from mysql. 2023-06-06 18:10:35,126 WARN manager.MySQLManager: This transfer can be faster! Use the --direct 2023-06-06 18:10:35,126 WARN manager.MySQLManager: option to exercise a MySQL-specific fast path. 2023-06-06 18:10:35,126 INFO manager.MySQLManager: Setting zero DATETIME behavior to convertToNull (mysql) 2023-06-06 18:10:35,130 ERROR tool.ImportTool: Import failed: No primary key could be found for table user_log. Please specify one with --split-by or perform a sequential import with '-m 1'.
时间: 2024-03-10 08:45:04 浏览: 166
这个错误提示表示Sqoop在导入数据时无法确定一个主键用于分片数据。这可能是由于你导入的表没有主键或你没有指定分片列导致的。
你可以尝试使用--split-by参数指定一个用于分片的列,或者使用-m 1参数指定只使用一个Mapper来导入数据。具体的命令如下:
1. 使用--split-by参数指定分片列:
```
sqoop import --connect jdbc:mysql://localhost:3306/mydatabase \
--username myuser --password mypassword \
--table user_log \
--split-by id
```
其中,id为你指定的分片列。
2. 使用-m 1参数只使用一个Mapper导入数据:
```
sqoop import --connect jdbc:mysql://localhost:3306/mydatabase \
--username myuser --password mypassword \
--table user_log \
-m 1
```
这样可以保证在导入数据时只使用一个Mapper,避免分片问题。但是,如果数据量很大,可能会导致导入速度变慢。
相关问题
[root@server1 sqoop]# bin/sqoop import-all-tables \ > --connect jdbc:mysql://192.168.88.132:3306/meta_erp_data \ > --username root \ > --password 666666 \ > --create-hive-database meta_erp_data \ > --hive-import --create-hive-table 2023-05-26 18:26:04,495 INFO sqoop.Sqoop: Running Sqoop version: 1.4.6-cdh5.14.2 2023-05-26 18:26:04,666 WARN tool.BaseSqoopTool: Setting your password on the command-line is insecure. Consider using -P instead. 2023-05-26 18:26:04,667 ERROR tool.BaseSqoopTool: Error parsing arguments for import-all-tables: 2023-05-26 18:26:04,667 ERROR tool.BaseSqoopTool: Unrecognized argument: --create-hive-database 2023-05-26 18:26:04,667 ERROR tool.BaseSqoopTool: Unrecognized argument: meta_erp_data 2023-05-26 18:26:04,667 ERROR tool.BaseSqoopTool: Unrecognized argument: --hive-import 2023-05-26 18:26:04,667 ERROR tool.BaseSqoopTool: Unrecognized argument: --create-hive-table Try --help for usage instructions.
根据您提供的错误信息,Sqoop无法识别`--create-hive-database`、`meta_erp_data`、`--hive-import`和`--create-hive-table`这些选项。这可能是因为您使用的Sqoop版本不支持这些选项。
请注意,`--create-hive-database`选项是从Sqoop 1.4.7版本开始支持的,而`--hive-import`和`--create-hive-table`选项是在Sqoop 1.4.0版本中引入的。因此,如果您的Sqoop版本太旧,则无法使用这些选项。
您可以尝试升级Sqoop版本,或者使用以下命令来导入所有表:
```
sqoop import-all-tables --connect jdbc:mysql://192.168.88.132:3306/meta_erp_data --username root --password 666666 --hive-import --hive-database meta_erp_data
```
这将从MySQL中导入所有表,并将它们存储到名为`meta_erp_data`的Hive数据库中。
[root@zhaosai conf]# sqoop import --connect jdbc:mysql://zhaosai:3306/mydb --username root --password jqe6b6 --table news --target-dir /user/news --fields-terminated-by “;” --hive-import --hive-table news -m 1 Warning: /opt/programs/sqoop-1.4.7.bin__hadoop-2.6.0/../hbase does not exist! HBase imports will fail. Please set $HBASE_HOME to the root of your HBase installation. Warning: /opt/programs/sqoop-1.4.7.bin__hadoop-2.6.0/../hcatalog does not exist! HCatalog jobs will fail. Please set $HCAT_HOME to the root of your HCatalog installation. Warning: /opt/programs/sqoop-1.4.7.bin__hadoop-2.6.0/../accumulo does not exist! Accumulo imports will fail. Please set $ACCUMULO_HOME to the root of your Accumulo installation. Warning: /opt/programs/sqoop-1.4.7.bin__hadoop-2.6.0/../zookeeper does not exist! Accumulo imports will fail. Please set $ZOOKEEPER_HOME to the root of your Zookeeper installation. 23/06/10 16:07:14 INFO sqoop.Sqoop: Running Sqoop version: 1.4.7 23/06/10 16:07:15 WARN tool.BaseSqoopTool: Setting your password on the command-line is insecure. Consider using -P instead. 23/06/10 16:07:15 INFO manager.MySQLManager: Preparing to use a MySQL streaming resultset. 23/06/10 16:07:15 INFO tool.CodeGenTool: Beginning code generation 23/06/10 16:07:15 ERROR sqoop.Sqoop: Got exception running Sqoop: java.lang.RuntimeException: Could not load db driver class: com.mysql.jdbc.Driver java.lang.RuntimeException: Could not load db driver class: com.mysql.jdbc.Driver at org.apache.sqoop.manager.SqlManager.makeConnection(SqlManager.java:875) at org.apache.sqoop.manager.GenericJdbcManager.getConnection(GenericJdbcManager.java:59) at org.apache.sqoop.manager.SqlManager.execute(SqlManager.java:763) at org.apache.sqoop.manager.SqlManager.execute(SqlManager.java:786) at org.apache.sqoop.manager.SqlManager.getColumnInfoForRawQuery(SqlManager.java:289) at org.apache.sqoop.manager.SqlManager.getColumnTypesForRawQuery(SqlManager.java:260) at org.apache.sqoop.manager.SqlManager.getColumnTypes(SqlManager.java:246) at org.apache.sqoop.manager.ConnManager.getColumnTypes(ConnManager.java:327) at org.apache.sqoop.orm.ClassWriter.getColumnTypes(ClassWriter.java:1872) at org.apache.sqoop.orm.ClassWriter.generate(ClassWriter.java:1671) at org.apache.sqoop.tool.CodeGenTool.generateORM(CodeGenTool.java:106) at org.apache.sqoop.tool.ImportTool.importTable(ImportTool.java:501) at org.apache.sqoop.tool.ImportTool.run(ImportTool.java:628) at org.apache.sqoop.Sqoop.run(Sqoop.java:147) at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70) at org.apache.sqoop.Sqoop.runSqoop(Sqoop.java:183) at org.apache.sqoop.Sqoop.runTool(Sqoop.java:234) at org.apache.sqoop.Sqoop.runTool(Sqoop.java:243) at org.apache.sqoop.Sqoop.main(Sqoop.java:252)
这段代码是使用 Sqoop 工具将 MySQL 数据库中的 news 表导入到 Hadoop 的 HDFS 中,并且使用 Hive 表示,并且在导入过程中使用了分隔符“;”。但是在执行过程中出现了一个异常,提示无法加载数据库驱动类 com.mysql.jdbc.Driver。可能是因为没有将 mysql-connector-java.jar 包添加到 Sqoop 的 classpath 中导致的。需要将该 jar 包添加到 Sqoop 的 lib 目录下,并重新执行该命令。
阅读全文