导包
import pymysql
import pandas as pd
获取mysql链接
def get_db():#打开数据库连接db = pymysql.connect(host='*.*.*.*',port=3306,user = "wws",passwd = "yourpasswd",db = "youdb")return db
db = get_db()
写sql 读数据保存
sql = "select `name`,`name_en`,`collage_name`,`description` from `yourdb`;"
#cursor= db.cursor()
sql_data = pd.read_sql_query(sql,db)
df = pd.DataFrame(sql_data, columns=[ 'name','name_en','collage_name','description'])
df
成了!