python从mysql读取数据的示例:
使用模块pandas、pymysql编写代码。
# -*- coding: utf-8 -*-import pandas as pd
import pymysql
dbconn = pymysql.connect(
host = "IP",
database = 'mysql',
user = 'root',
password = '******'
)
sql = 'select * from user'
a= pd.read_sql(sql,dbconn)
b = a.head()
print(b)