Apache Zeppelin报ava.lang.ClassNotFoundException: com.mysql.jdbc.Driver错误求助
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in Apache Zeppelin Got it, let's break down why you're running into this error and walk through the fixes step by step.
First, looking at your interpreter config, there are two key issues that are causing the driver not to be found:
1. Typo in the Driver Class Name
Your default.driver is set to org.mysql.jdbc.Driver – but the correct fully qualified class name for MySQL 5.x connectors is com.mysql.jdbc.Driver. The org prefix here is a mistake that's preventing Zeppelin from locating the driver class.
2. Incorrect Dependency Configuration
The Dependencies line uses exclude, which tells Zeppelin to ignore the specified JAR file. But we need Zeppelin to include this driver JAR to connect to MySQL. Plus, the syntax for referencing a local JAR is off when using exclude.
Step-by-Step Solutions
Correct the Driver Class
- Open your Zeppelin UI and navigate to the Interpreter page.
- Find the JDBC interpreter and edit its settings.
- Locate the
default.driverproperty and update its value to:
(Note: If you were using MySQL 8.0+, this would becom.mysql.jdbc.Drivercom.mysql.cj.jdbc.Driver, but since your connector is 5.1.46, stick with the above.)
Fix the Dependency Setup
You have two options here, pick whichever works better for you:
Option A: Use Maven Artifact (Recommended)
Instead of relying on a local JAR, let Zeppelin handle downloading the driver via Maven. Update the Dependencies field to:
mysql:mysql-connector-java:5.1.46
Zeppelin will automatically fetch this artifact and its dependencies if they aren't already in your local repo.
Option B: Use Your Local JAR
If you want to use the existing JAR at /usr/local/zeppelin/interpreter/jdbc/mysql-connector-java-5.1.46-bin.jar, change the Dependencies line to just:
/usr/local/zeppelin/interpreter/jdbc/mysql-connector-java-5.1.46-bin.jar
Remove the exclude keyword entirely. Also, double-check that the JAR exists at that path and that the Zeppelin process has read permissions for it.
Restart the Interpreter
After making these changes, save the interpreter settings and restart the JDBC interpreter. This ensures the new config and driver are loaded properly.
Additional Checks
- Test if you can connect to MySQL from the Zeppelin server using the same credentials: Run
mysql -u root -pin the terminal and enter your password. If this fails, fix the MySQL connection first before troubleshooting Zeppelin. - Ensure your
default.urlis complete (it should include the database name, e.g.,jdbc:mysql://localhost:3306/your_database_name– without the database name, you might hit connection issues even after fixing the driver).
Once you've applied these fixes, try running your JDBC note again – the ClassNotFoundException should be resolved.
内容的提问来源于stack exchange,提问作者immortal

