python 连接Mysql
import pymysqlimport pandas as pd# 打开数据库连接conn = pymysql.connect( host='host', port=3306, charset ='utf8', user='username', passwd='pwd', db='db_name')# 使用 cursor() 方法创建一个游标对象 cursorcur = conn.cursor()# 使用 execute() 方法执行 SQL 查询cursor.execute("SELECT VERSION()")cursor.execute(sql)# 获取所有记录列表results = cursor.fetchall()for row in results: fname = row[0] lname = row[1] age = row[2] sex = row[3] income = row[4]这样还是比较麻烦,有更好的方法直接写入Data 中
import pymysqlimport pandas as pdconn = pymysql.connect( host='host', port=3306, charset ='utf8', user='username', passwd='pwd', db='db_name')# 直接返回得到Data df = pd.read_sql(sql,conn) 继续阅读与本文标签相同的文章
上一篇 :
区块链主链开发公司谈区块链侧链的价值
下一篇 :
Shell中的一个知识点
-
ES6(Module 模块化)
2026-05-26栏目: 教程
-
ES6(Decorator(修饰器)
2026-05-26栏目: 教程
-
ES6(Generator)
2026-05-26栏目: 教程
-
ES6(Iterator 和 for...of 循环)
2026-05-26栏目: 教程
-
ES6(Promise)
2026-05-26栏目: 教程
