Data Science/Python

[Python] Transfer Pandas Dataframe to MYSQL database with SSH

DS-9VM 2023. 2. 22. 23:03
728x90

in the terminal for local port forwarding:

ssh -N -v username@hostname -L3306:127.0.0.1:3306

 

sqlalchemy for the connection :

from sqlalchemy import create_engine

engine = create_engine("mysql+pymysql://user:password@127.0.0.1:3306/dbname?charset=utf8"

df.to_sql(con=engine, name='dest_table', if_exists='replace')

 

https://unsplash.com/photos/ieic5Tq8YMk

 

728x90