Created
June 30, 2022 06:28
-
-
Save yaojenkuo/a757196d8dd9fb8fdc802edbd6a8db69 to your computer and use it in GitHub Desktop.
Export table from SQLite and import to MySQL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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