Writing a Pandas Dataframe to MySQL
<p>I'm trying to write a Python Pandas Dataframe to a MySQL database. I realize that it's possible to use sqlalchemy <a href="http://stackoverflow.com/questions/37627520/insert-pandas-dataframe-to-mysql-using-sqlalchemy">for this</a>, but I'm wondering if there is another way that may be easier, preferably already built into Pandas. I've spent quite some time trying to do it with a For loop, but it's not realiable. </p>

<p>If anyone knows of a better way, it would be greatly appreciated.</p>

<p>Thanks a lot!</p>

<p>The other option to <strong>sqlalchemy</strong> can be used <strong>to_sql</strong> but in future released will be deprecated but now in version <strong>pandas 0.18.1 documentation</strong> is still active. </p>

<p>According to pandas documentation <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_sql.html" rel="nofollow">pandas.DataFrame.to_sql</a> you can use following syntax:</p>

<pre><code>DataFrame.to_sql(name, con, flavor='sqlite', schema=None, if_exists='fail', index=True, index_label=None, chunksize=None, dtype=None)
</code></pre>

<p>you specify the con <strong>type/mode</strong> and flavor <strong>âmysqlâ</strong>, here is some description:</p>

<blockquote>
  <p>con : SQLAlchemy engine or DBAPI2 connection (legacy mode)
  Using SQLAlchemy makes it possible to use any DB supported by that library. If a DBAPI2 object, only sqlite3 is supported.</p>
  
  <p>flavor : {âsqliteâ, âmysqlâ}, default âsqliteâ The flavor of SQL to
   use. Ignored when using SQLAlchemy engine. âmysqlâ is deprecated and
   will be removed in future versions, but it will be further supported
   through SQLAlchemy engines.</p>
</blockquote>

python mysql dataframe