python-mysql的连接操作

1.如何用python连接数据库并进行相关操作

import pymysql

#数据库的相关信息

dbconn=pymysql.connect(host="114.113.151.71",user="fd_data",password="fd_data",port=3306,database='financialdata')

#数据库语句

sqlcmd="SELECT CODE FROM tbl_fund_info  WHERE (investment_objectives ='' OR investment_objectives IS NULL) OR (investment_strategy IS NULL OR investment_strategy='') OR (characteristics IS NULL OR characteristics='');"

#连接语句

a=pd.read_sql(sqlcmd,dbconn)

#a出来是dateframe格式,取其中的某些列变化成list

a=a['CODE']
list=a.tolist()

猜你喜欢

转载自blog.csdn.net/cxlhuihui/article/details/80001696