python3连接mysql的方式:
def mysql_(): conn = pymysql.connect(host='127.0.0.1', user='用户名', passwd='密码', db='数据库', port=3306, charset='utf8', cursorclass=pymysql.cursors.DictCursor) cur = conn.cursor() return conn,cur if __name__=="__main__": conn,cur=mysql_() select_sql="select 列名 from 表名" cur.execute(select_sql) domain_list=cur.fetchall() for i in domain_list: print(i)