import pandas as pd
import numpy as np
import pymysql
%%打开数据库连接
conn = pymysql.connect(host='地址',user = "用户",passwd = "密码",
db = "数据库")
sql1 = '''
'''
sql_data1 = pd.read_sql_query(sql1,conn)
import pymysql
conn = pymysql.connect(host="地址",port=3306,user="用户",password="密码",database="数据库")
cursor = conn.cursor()
sqls1 = "drop table if exists " #如果存在就删除
cursor.execute(sqls1)
cursor.close()
conn.close()
import pymysql
import pandas as pd
from sqlalchemy import create_engine
conn = pymysql.connect(host='地址',user = "用户",passwd = "密码",
db = "数据库")
读取数据
建立连接,username替换为用户名,passwd替换为密码,test替换为数据库名
conn = create_engine('mysql+pymysql://用户:密码@地址:端口/数据库',encoding='utf8')
写入数据,table_name为表名,‘replace’表示如果同名表存在就替换掉
cddyx.to_sql("", conn, if_exists='replace', index=False)
查看库的表名
show TABLES
安装
https://blog.csdn.net/weixin_39289696/article/details/128850498