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)