title: Pandas 0.20.2 to_sql() using MySQL
body: <p>I'm trying to write a dataframe to a MySQL table but am getting a <code>(111 Connection refused)</code> error.</p>
  
  <p>I followed the accepted answer here:
  <a href="https://stackoverflow.com/questions/30631325/writing-to-mysql-database-with-pandas-using-sqlalchemy-to-sql">Writing to MySQL database with pandas using SQLAlchemy, to_sql</a></p>
  
  <p>Answer's code:</p>
  
  <pre><code>import pandas as pd
  import mysql.connector
  from sqlalchemy import create_engine
  
  engine = create_engine('mysql+mysqlconnector://[user]:[pass]@[host]:[port]/[schema]', echo=False)
  data.to_sql(name='sample_table2', con=engine, if_exists = 'append', index=False)
  </code></pre>
  
  <p>...and the <code>create_engine()</code> line worked without error, but the <code>to_sql()</code> line failed with this error:</p>
  
  <pre><code>(mysql.connector.errors.InterfaceError) 2003: Can't connect to MySQL server on 'localhost:3306' (111 Connection refused)
  </code></pre>
  
  <p>How I connect to my MySQL database / table is not really relevant, so completely different answers are appreciated, but given the <a href="https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_sql.html" rel="nofollow noreferrer">deprecation of the MySQL 'flavor' in pandas 0.20.2</a>, what is the proper way to write a dataframe to MySQL?</p>