0
import mysql.connector
from pyspark.sql import SparkSession


spark = SparkSession.builder.config("spark.jars", "/usr/share/java/mysql-connector-java-8.0.29.jar")\
        .master("local").appName("Integrated_ca2").getOrCreate()



connection = mysql.connector.connect(user='root', database='tweets',
                                     password='password',host='localhost'
                                     ,auth_plugin='mysql_native_password')
cursor = connection.cursor()

cursor.execute("USE tweets;")

f = spark.read.format("jdbc").option("url", "jdbc:mysql://localhost:8888/tweets") \
    .option("driver", "com.mysql.jdbc.Driver").option("dbtable","tweets_ca2").option("user", "root").option("password","password").load()

cursor.execute('select * from tweets_ca2;')

the error is Py4JJavaError: An error occurred while calling o321.load. : java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

Paul Corcoran
  • 113
  • 1
  • 9
  • 1
    curious question, is `com.mysql.jdbc.Driver` installed already? its in classpath? ubuntu community has a note on installing [mysql jdbc driver](https://help.ubuntu.com/community/JDBCAndMySQL). you can also install it manually through [package](https://askubuntu.com/a/1339372) or [zip](https://stackoverflow.com/a/5307060). – Bagus Tesa May 15 '22 at 13:40
  • Driver is probably not on classpath – Thorbjørn Ravn Andersen May 15 '22 at 13:59

0 Answers0