Forums
How to write data to a sql table using python? - Printable Version

+- Forums (https://bdn.bdb.ai)
+-- Forum: BDB Knowledge Base (https://bdn.bdb.ai/forumdisplay.php?fid=13)
+--- Forum: BDB Data Pipeline (https://bdn.bdb.ai/forumdisplay.php?fid=48)
+---- Forum: BDB Data Pipeline Q & A (https://bdn.bdb.ai/forumdisplay.php?fid=17)
+---- Thread: How to write data to a sql table using python? (/showthread.php?tid=348)



How to write data to a sql table using python? - shreekantgosavi - 12-21-2022

Use python script component.
Paste below script in meta information script section.
Provide connection credentials.

import pandas as pd
from sqlalchemy import create_engine
def sql_write(data):

   # Connect to the database
   engine = create_engine('mysql+pymysql://user:password@host/database')

   # Store the data in the database
   data.to_sql('table_name', engine, if_exists='replace')