Cant able to connect sqlContext in Itversity lab


SqlContext is getting exception while connecting in Itversity lab.
I am connecting this using spark-shell

scala> val sqlcontext = new org.apache.spark.sql.SQLContext(sc)
sqlcontext: org.apache.spark.sql.SQLContext = org.apache.spark.sql.SQLContext@4dd2f2db

scala> val dataframe_mysql ="jdbc").option("url", "jdbc:mysql://").option("driver", "com.mysql.jdbc.Driver").option("dbtable", "orders").option("user", "retail_dba").option("password", "itversity").load()
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
        at java.lang.ClassLoader.loadClass(
        at java.lang.ClassLoader.loadClass(

Could any one please advice me how to connect mysql in spark.

Learn Spark 1.6.x or Spark 2.x on our state of the art big data labs

  • Click here for access to state of the art 13 node Hadoop and Spark Cluster

@raki28 Launch spark-shell as below command.

spark-shell --jars /usr/share/java/mysql-connector-java.jar

Try below query

val dataframe_mysql ="jdbc").option("url", "jdbc:mysql://").option("driver", "com.mysql.jdbc.Driver").option("dbtable", "orders").option("user", "retail_user").option("password", "itversity").load()

1 Like

Thank you very much @annapurna.