from sqlalchemy import create_engine

239 阅读1分钟
from sqlalchemy import create_engine

host = '10.x.x.x'
user = 'xxxx'
password = 'xxxxx'
port = 'xxx'
database = 'xxxx'
engine_str = 'postgres://' + user + ':' + password + '@' + host + ':' + port + '/' + database

conn = create_engine(engine_str)
sql = "delete  FROM aaa_test_ma_biao where 序列號='FCQ1544Y4PS'"
conn.execute(sql)


# dataframe 写入 数据库中
data_df.to_sql("table_name",if_exists="append",con=conn,index=False)

# 理解一下
通过host,user,password,port,database等数据,
然后通过create_engine()函数,我们可以得到一个简称为conn的一把刀
这把刀可以对数据库进行各种操作。

conn.extcute(sql_command)