Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yaojenkuo/a757196d8dd9fb8fdc802edbd6a8db69 to your computer and use it in GitHub Desktop.
Save yaojenkuo/a757196d8dd9fb8fdc802edbd6a8db69 to your computer and use it in GitHub Desktop.
Export table from SQLite and import to MySQL.
from sqlalchemy import create_engine
from urllib.parse import quote
import sqlite3
import pandas as pd
password = "YOURPASSWORD"
db_name = "YOURDBNAME"
table_name = "YOURTABLENAME"
connection_url = "mysql+pymysql://root:{0}@localhost:3306/{1}".format(quote(password), db_name)
engine = create_engine(connection_url)
sqlite_connection = sqlite3.connect("{}.db".format(db_name))
dataframe = pd.read_sql("""YOURSQLQUERY""", sqlite_connection)
dataframe.to_sql(table_name, con=engine, if_exists="replace")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment