title: How to connect spark with mysql using pycharm
body: <p>i try to select a table content from mysql database to a dataframe,
  i follow this steps to connect spark with mysql.</p>
  
  <ol>
  <li>download <code>mysql-connector-java-5.0.8-bin.jar</code></li>
  <li>i put <code>mysql-connector-java-5.0.8-bin.jar</code> at path <code>$SPARK_HOME/bin/mysql-connector-java-5.0.8-bin.jar</code> 
  but it still not work     </li>
  </ol>
  
  <p>Code:</p>
  
  <pre><code>from pyspark import SparkContext
  from pyspark.sql import SQLContext, Row
  
  sc = SparkContext()
  sqlctx = SQLContext(sc)
  
  
   dataframe_mysql = sqlctx.read.format("jdbc").options(
      url="jdbc:mysql://localhost:3306/database",
      driver="com.mysql.jdbc.Driver",
      dbtable="user",
      user="root",
      password="").load()
  </code></pre>
  
  <p>after that i tried to connect spark with mysql using cmd 
  Start the pyspark shell with –jars argument</p>
  
  <pre><code>$SPARK_HOME/bin/pyspark  –-jars mysql-connector-java-5.0.8-bin.jar
  </code></pre>
  
  <p>and also not work
  i not understand why using driver="com.mysql.jdbc.Driver"
  to connect to mysql
  can anyone help me
   thanks in advance</p>
  
  <p>i got this error</p>
  
  <pre><code>File "C:/Users/kcs/PycharmProjects/Flunky/SparkMySql.py", line 14, in &lt;module&gt;
    password="").load()
    File "C:\DataScience\python\pyspark\sql\readwriter.py", line 123, in load
    return self._df(self._jreader.load())
    File "C:\DataScience\python\lib\py4j-0.8.2.1-          src.zip\py4j\java_gateway.py", line 538, in __call__
    File "C:\DataScience\python\pyspark\sql\utils.py", line 36, in deco
     return f(*a, **kw)
     File "C:\DataScience\python\lib\py4j-0.8.2.1-src.zip\py4j\protocol.py",     line 300, in get_return_value
   py4j.protocol.Py4JJavaError: An error occurred while calling o24.load.
   : java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
  at java.net.URLClassLoader.findClass(Unknown Source)
  at java.lang.ClassLoader.loadClass(Unknown Source)
  at java.lang.ClassLoader.loadClass(Unknown Source)
  at org.apache.spark.sql.execution.datasources.jdbc.DriverRegistry$.register(DriverRegistry.scala:38)
  at org.apache.spark.sql.execution.datasources.jdbc.DefaultSource.createRelation(DefaultSource.scala:41)
  at org.apache.spark.sql.execution.datasources.ResolvedDataSource$.apply(ResolvedDataSource.scala:125)
  at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:114)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  at java.lang.reflect.Method.invoke(Unknown Source)
  at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:231)
  at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:379)
  at py4j.Gateway.invoke(Gateway.java:259)
  at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:133)
  at py4j.commands.CallCommand.execute(CallCommand.java:79)
  at py4j.GatewayConnection.run(GatewayConnection.java:207)
  at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p><a href="http://i.stack.imgur.com/O5z3B.png" rel="nofollow">and the error on cmd is</a></p>