Sqoop:无法加载 mysql 驱动程序异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22741183/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 20:19:48  来源:igfitidea点击:

Sqoop: Could not load mysql driver exception

mysqlhadoophivesqoop

提问by Sam

I Installed Sqoop in my local machine. Following are the config information.

我在本地机器上安装了 Sqoop。以下是配置信息。

Bash.bashrc:

bash.bashrc:

export HADOOP_HOME=/home/hduser/hadoop
export HBASE_HOME=/home/hduser/hbase
export HIVE_HOME=/home/hduser/hive
export HCAT_HOME=/home/hduser/hive/hcatalog
export SQOOP_HOME=/home/hduser/sqoop

export PATH=$PATH:$HIVE_HOME/bin
export PATH=$PATH:$HADOOP_HOME/bin
export PATH=$PATH:$HBASE_HOME/bin
export PATH=$PATH:$SQOOP_HOME/bin
export PATH=$PATH:$HCAT_HOME/bin

Hadoop:

Hadoop:

Version: Hadoop 1.0.3

Hive:

蜂巢:

Version: hive 0.11.0 

Mysql Connector driver

Mysql 连接器驱动程序

version: mysql-connector-java-5.1.29

"The driver is copied to the lib folder of sqoop"

Sqoop :

Sqoop :

version: sqoop 1.4.4

After making all the installation I create a table in mysql named practice_1, But when I run the load command to load data from mysql to hdfs the command throws an exception:

完成所有安装后,我在 mysql 中创建了一个名为 practice_1 的表,但是当我运行 load 命令将数据从 mysql 加载到 hdfs 时,该命令引发异常:

ERROR sqoop.Sqoop: Got exception running Sqoop: java.lang.RuntimeException: Could not     load db driver class: com.mysql.jdbc.Driver

Coud anyone please guide me what can be the possible problem.

任何人都可以指导我可能出现的问题。

回答by malatesh

You need database driver in 'SQOOP' classpath check thisIt has wonderful explanation about the 'SQOOP'

您需要'SQOOP'类路径中的数据库驱动程序检查这个它对'SQOOP'有很好的解释

SQOOP has other options like

SQOOP 有其他选项,如

Ex: --driver com.microsoft.jdbc.sqlserver.SQLServerDriver -libjars=".*jar"

例如:--driver com.microsoft.jdbc.sqlserver.SQLServerDriver -libjars=".*jar"

from here

这里

You can use Sqoop with any other JDBC-compliant database. First, download the appropriate JDBC driver for the type of database you want to import, and install the .jar file in the $SQOOP_HOME/lib directory on your client machine. (This will be /usr/lib/sqoop/lib if you installed from an RPM or Debian package.) Each driver .jar file also has a specific driver class which defines the entry-point to the driver. For example, MySQL's Connector/J library has a driver class of com.mysql.jdbc.Driver. Refer to your database vendor-specific documentation to determine the main driver class. This class must be provided as an argument to Sqoop with --driver.

您可以将 Sqoop 与任何其他符合 JDBC 的数据库一起使用。首先,为要导入的数据库类型下载相应的 JDBC 驱动程序,然后在客户端计算机的 $SQOOP_HOME/lib 目录中安装 .jar 文件。(如果您是从 RPM 或 Debian 软件包安装的,这将是 /usr/lib/sqoop/lib。)每个驱动程序 .jar 文件还有一个特定的驱动程序类,用于定义驱动程序的入口点。例如,MySQL 的 Connector/J 库有一个驱动程序类 com.mysql.jdbc.Driver。请参阅特定于数据库供应商的文档以确定主要驱动程序类。必须使用 --driver 将此类作为参数提供给 Sqoop。

You may be interested in understanding the difference between connector and driver hereis the article

您可能有兴趣了解连接器和驱动程序之间的区别,这里是文章

回答by selle

Another solution which avoids using a shared library is adding the driver jar to the classpath of sqoop by using HADOOP_CLASSPATH. I haven't got the -libjars option to work. This solution works also on a secure cluster using kerberos.

另一个避免使用共享库的解决方案是使用 HADOOP_CLASSPATH 将驱动程序 jar 添加到 sqoop 的类路径。我没有使用 -libjars 选项。此解决方案也适用于使用 kerberos 的安全集群。

HADOOP_CLASSPATH=/use.case/lib/postgresql-9.2-1003-jdbc4.jar
sqoop export --connect jdbc:postgresql://db:5432/user \
  --driver org.postgresql.Driver \
  --connection-manager org.apache.sqoop.manager.GenericJdbcManager \
  --username user \
  -P \
  --export-dir /user/hive/warehouse/db1/table1 \
  --table table2

This one works at least with sqoop 1.4.3-cdh4.4.0

这个至少适用于 sqoop 1.4.3-cdh4.4.0

回答by Mukesh S

You need to add the MySql connector to /usr/lib/sqoop/lib. MySQL JDBC Driver by default is not present in Sqoop distribution in order to ensure that the default distribution is fully Apache license compliant. Hope this helps...!!!

您需要将 MySql 连接器添加到 /usr/lib/sqoop/lib。默认情况下,Sqoop 发行版中不存在 MySQL JDBC 驱动程序,以确保默认发行版完全符合 Apache 许可证。希望这可以帮助...!!!

回答by Kumar

If you have copied mysql driver to the sqoop lib folder. It will work for sure. Make sure you sqoop command is correct

如果您已将 mysql 驱动程序复制到 sqoop lib 文件夹。它肯定会起作用。确保你的 sqoop 命令是正确的

/home/hduser/sqoop/bin/sqoop import --connect jdbc:mysql://localhost:3306/test --username root --password root -–table practice_1 -m 1

回答by y durga prasad

copy the 'mysql-connector-java-5.1.41-bin.jar' into sqoop/lib folder and execute sqoop import statements

将'mysql-connector-java-5.1.41-bin.jar'复制到sqoop/lib文件夹并执行sqoop导入语句

回答by Henrique Dias

It's a Oozie ShareLib problem. The script below works for my:

这是一个 Oozie ShareLib 问题。下面的脚本适用于我的:

At Shell

在壳牌

sudo -u hdfs hadoop fs -chown cloudera:cloudera /user/oozie/share/lib/lib_20170719053712/sqoop
hdfs dfs -put /var/lib/sqoop/mysql-connector-java.jar /user/oozie/share/lib/lib_20170719053712/sqoop
sudo -u hdfs hadoop fs -chown oozie:oozie /user/oozie/share/lib/lib_20170719053712/sqoop

oozie admin -oozie http://localhost:11000/oozie -sharelibupdate
oozie admin -oozie http://localhost:11000/oozie -shareliblist sqoop

At Hue Sqoop Client

在 Hue Sqoop 客户端

sqoop list-tables --connect jdbc:mysql://localhost/retail_db --username root --password cloudera

More detail at:

更多详情请访问:

https://blog.cloudera.com/blog/2014/05/how-to-use-the-sharelib-in-apache-oozie-cdh-5/

https://blog.cloudera.com/blog/2014/05/how-to-use-the-sharelib-in-apache-oozie-cdh-5/

回答by Chalpat

You need to grant privelegesto the tables as below:

您需要授予priveleges以下表格:

grant all privileges on marksheet.* to 'root'@'192.168.168.1' identified by 'root123';

flush privileges;

将 marksheet.* 上的所有权限授予由 'root123' 标识的 'root'@'192.168.168.1';

刷新权限;

Here is sample command that I have successfully executed:

这是我已成功执行的示例命令:

sqoop import --verbose --fields-terminated-by ',' --connect jdbc:mysql://192.168.168.1/test --username root --password root123 --table student --hive-import --create-hive-table --hive-home /home/training/hive --warehouse-dir /user/hive/warehouse --fields-terminated-by ',' --hive-table studentmysql

sqoop import --verbose --fields-terminated-by ',' --connect jdbc:mysql://192.168.168.1/test --username root --password root123 --table student --hive-import --create- hive-table --hive-home /home/training/hive --warehouse-dir /user/hive/warehouse --fields-terminated-by ',' --hive-table studentmysql