'How to drive the whole pandas DataFrame to SQL table

I'm using sqlalchemy , pyodbc, pandas to write the pandas dataframe into the table in SQL DB, my code like below:

import pandas as pd
import sqlalchemy
import pyodbc
#load file excel to update DB
df1 = pd.read_excel(r'C:\Users\user\Downloads\update_.xlsx')
#setup connection 

engine = create_engine("mysql+pymysql://{user}:{pw}@{host}/{db}".format(user="sa",pw="Welcome1",host="localhost",db="test"))
# write the DataFrame to a table in the sql database
df1.to_sql("dbo.test2", engine, if_exists='append')  
#my DB name is: "test" , and table need to insert data is "dbo.test2"

my hosts file in C:\system32\drivers\etc configured:

127.0.0.1       localhost
#   ::1             localhost

i got the error below:

OperationalError: (pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on 'THANG' ([WinError 10061] No connection could be made because the target machine actively refused it)")
(Background on this error at: https://sqlalche.me/e/14/e3q8)

PS: i have enable SQL server browser already , tried to restart SQL server but no luck , could you please help assist ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source