Python & Pandas : (pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on 'localhost' (timed out)")
The following works for me:

df.to_sql(con="mysql://user:password@localhost/database_name, name='myTable2', if_exists='replace')