title: How to read & write Local MySQL Server 8 from Google Colab with Pyspark?
body: <p>I have been trying but failing to write/read tables from MySQL Server 8.0.19 on localhost on Windows 10 with pyspark from Google colab. There's also a lot of similar questions and with some suggested answers but none of the solutions seem to work here. Here is my code:</p>
  
  <pre><code>    &lt;...installations  ...&gt;
  
          from pyspark.sql import SparkSession
  
          spark = SparkSession\
          .builder\
          .appName("Word Count")\
          .config("spark.driver.extraClassPath", "/content/spark-2.4.5-bin-hadoop2.7/jars/mysql-connector-java-8.0.19.jar")\
          .getOrCreate()
  </code></pre>
  
  <p>An here is the connection string:</p>
  
  <pre><code>MyjdbcDF = spark.read.format("jdbc")\
                      .option("url", "jdbc:mysql://127.0.0.1:3306/mydb?user=testuser&amp;password=pwtest")\
                      .option("dbtable", "collisions")\
                      .option("driver","com.mysql.cj.jdbc.Driver")\
                      .load()
  </code></pre>
  
  <p>I have as well used the <code>.option("driver","com.mysql.jdbc.Driver")</code> but still keep getting this error:</p>
  
  <pre><code>Py4JJavaError: An error occurred while calling o154.load.
  com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
  
  The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
  
  ...
  ...
  ...
  Caused by: java.net.ConnectException: Connection refused (Connection refused)
  </code></pre>
  
  <p>From this, I guess that MySQL Sever is not reachable. 
  I have Telnetted to port 3306 &amp; it confirmed that MySQL Server is accepting connections from client machine. I have read that running: <code>netsh advfirewall firewall add rule name="MySQL Server" action=allow protocol=TCP dir=in localport=3306</code> will permitting firewall rule for MySQL Server incase it was being blocked, yet no change.</p>
  
  <p>Can somebody help outpy?</p>