title: How to set up JDBC driver for MySQL in Jupyter notebook for pyspark?
body: <p>I am trying to load a bunch of CSV files row by row into mysql instance which is running on OpenShift using pyspark configuration. I have a Jupyter notebook with spark up and running.</p>
  <p>Below is the code I have. And it fails with specific driver error</p>
  <pre><code>Py4JJavaError: An error occurred while calling o89.save.
  </code></pre>
  <pre class="lang-py prettyprint-override"><code>
  from pyspark.sql import SparkSession
  from pyspark.sql import SQLContext
  
  if __name__ == '__main__':
      scSpark = SparkSession \
          .builder \
          .appName(&quot;reading csv&quot;) \
          .getOrCreate()
  
  if __name__ == '__main__':
      scSpark = SparkSession \
          .builder \
          .appName(&quot;reading csv&quot;) \
          .getOrCreate()
      
  data_file = '/opt/app-root/src/data/train.psv'
  sdfData = scSpark.read.csv(data_file, header=True, sep=&quot;|&quot;).cache()
  print('Total Records = {}'.format(sdfData.count()))
  sdfData.show()
  
  sdfData.registerTempTable(&quot;train&quot;)
  output =  scSpark.sql('SELECT count(*) from train')
  output.show()
  
  +--------+
  |count(1)|
  +--------+
  | 1168686|
  +--------+
  
  import os
  os.environ['PYSPARK_SUBMIT_ARGS'] = '--packages mysql:mysql-connector-java:jar:8.0.21 pyspark-shell'
  
  output = scSpark.sql('SELECT * from train')
  output.show()
  output.write.format('jdbc').options(
      url='jdbc:mysql://mysql-1-28d85/sepsis',
      driver='com.mysql.jdbc.Driver',
      #driver='mysql-connector-java.Driver',
      #driver='org.mysql.jdbc.Driver',
      dbtable='train',
      user='sepsis',
      password='Success_2020').mode('append').save()
  
  
  ---------------------------------------------------------------------------
  Py4JJavaError                             Traceback (most recent call last)
  &lt;ipython-input-57-114af97e0442&gt; in &lt;module&gt;
       11     dbtable='train',
       12     user='sepsis',
  ---&gt; 13     password='Success_2020').mode('append').save()
  
  /opt/app-root/lib/python3.6/site-packages/pyspark/sql/readwriter.py in save(self, path, format, mode, partitionBy, **options)
      735             self.format(format)
      736         if path is None:
  --&gt; 737             self._jwrite.save()
      738         else:
      739             self._jwrite.save(path)
  
  /opt/app-root/lib/python3.6/site-packages/py4j/java_gateway.py in __call__(self, *args)
     1255         answer = self.gateway_client.send_command(command)
     1256         return_value = get_return_value(
  -&gt; 1257             answer, self.gateway_client, self.target_id, self.name)
     1258 
     1259         for temp_arg in temp_args:
  
  /opt/app-root/lib/python3.6/site-packages/pyspark/sql/utils.py in deco(*a, **kw)
       61     def deco(*a, **kw):
       62         try:
  ---&gt; 63             return f(*a, **kw)
       64         except py4j.protocol.Py4JJavaError as e:
       65             s = e.java_exception.toString()
  
  /opt/app-root/lib/python3.6/site-packages/py4j/protocol.py in get_return_value(answer, gateway_client, target_id, name)
      326                 raise Py4JJavaError(
      327                     &quot;An error occurred while calling {0}{1}{2}.\n&quot;.
  --&gt; 328                     format(target_id, &quot;.&quot;, name), value)
      329             else:
      330                 raise Py4JError(
  
  Py4JJavaError: An error occurred while calling o1641.save.
  : java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
      at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
      at org.apache.spark.sql.execution.datasources.jdbc.DriverRegistry$.register(DriverRegistry.scala:45)
      at org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions$$anonfun$5.apply(JDBCOptions.scala:99)
      at org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions$$anonfun$5.apply(JDBCOptions.scala:99)
      at scala.Option.foreach(Option.scala:257)
      at org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions.&lt;init&gt;(JDBCOptions.scala:99)
      at org.apache.spark.sql.execution.datasources.jdbc.JdbcOptionsInWrite.&lt;init&gt;(JDBCOptions.scala:190)
      at org.apache.spark.sql.execution.datasources.jdbc.JdbcOptionsInWrite.&lt;init&gt;(JDBCOptions.scala:194)
      at org.apache.spark.sql.execution.datasources.jdbc.JdbcRelationProvider.createRelation(JdbcRelationProvider.scala:45)
      at org.apache.spark.sql.execution.datasources.SaveIntoDataSourceCommand.run(SaveIntoDataSourceCommand.scala:45)
      at org.apache.spark.sql.execution.command.ExecutedCommandExec.sideEffectResult$lzycompute(commands.scala:70)
      at org.apache.spark.sql.execution.command.ExecutedCommandExec.sideEffectResult(commands.scala:68)
      at org.apache.spark.sql.execution.command.ExecutedCommandExec.doExecute(commands.scala:86)
      at org.apache.spark.sql.execution.SparkPlan$$anonfun$execute$1.apply(SparkPlan.scala:131)
      at org.apache.spark.sql.execution.SparkPlan$$anonfun$execute$1.apply(SparkPlan.scala:127)
      at org.apache.spark.sql.execution.SparkPlan$$anonfun$executeQuery$1.apply(SparkPlan.scala:155)
      at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:151)
      at org.apache.spark.sql.execution.SparkPlan.executeQuery(SparkPlan.scala:152)
      at org.apache.spark.sql.execution.SparkPlan.execute(SparkPlan.scala:127)
      at org.apache.spark.sql.execution.QueryExecution.toRdd$lzycompute(QueryExecution.scala:83)
      at org.apache.spark.sql.execution.QueryExecution.toRdd(QueryExecution.scala:81)
      at org.apache.spark.sql.DataFrameWriter$$anonfun$runCommand$1.apply(DataFrameWriter.scala:676)
      at org.apache.spark.sql.DataFrameWriter$$anonfun$runCommand$1.apply(DataFrameWriter.scala:676)
      at org.apache.spark.sql.execution.SQLExecution$$anonfun$withNewExecutionId$1.apply(SQLExecution.scala:80)
      at org.apache.spark.sql.execution.SQLExecution$.withSQLConfPropagated(SQLExecution.scala:127)
      at org.apache.spark.sql.execution.SQLExecution$.withNewExecutionId(SQLExecution.scala:75)
      at org.apache.spark.sql.DataFrameWriter.runCommand(DataFrameWriter.scala:676)
      at org.apache.spark.sql.DataFrameWriter.saveToV1Source(DataFrameWriter.scala:285)
      at org.apache.spark.sql.DataFrameWriter.save(DataFrameWriter.scala:271)
      at sun.reflect.GeneratedMethodAccessor67.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
      at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
      at py4j.Gateway.invoke(Gateway.java:282)
      at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
      at py4j.commands.CallCommand.execute(CallCommand.java:79)
      at py4j.GatewayConnection.run(GatewayConnection.java:238)
      at java.lang.Thread.run(Thread.java:748)
  </code></pre>
  <p>Changed the code with package.</p>
  <p>Also this is openshift , where all components are running as pods with no access to outside environment.</p>