错误原因:导入sql的方式更新了
解决方法:
import pandas as pd
from sqlalchemy import create_engine
MYSQL_HOST = 'localhost'
MYSQL_PORT = '3306'
MYSQL_USER = 'root'
MYSQL_PASSWORD = '123456'
MYSQL_DB = 'cldk_data'
engine = create_engine('mysql+pymysql://%s:%s@%s:%s/%s?charset=utf8'
% (MYSQL_USER, MYSQL_PASSWORD, MYSQL_HOST, MYSQL_PORT, MYSQL_DB))
data=pd.read_sql('select * from pt_user',engine)
print(data)
运行结果:
D:\Python\p\Scripts\python.exe "D:\Python\python-learning\数据分析(二)\读取文件.py"
USER_UUID USER_NAME ... DEL_FLAG MODTIME
0 001fddf8608c4cd1bbac81dde4e0c701 zhaowei ... 0 2022-11-16 17:07:01
1 011d83b63034470ab6225a2ead643cf7 hanguobing ... 0 2022-11-16 17:07:01
2 01635ed157e445bba6725675bdd8ff67 renjun ... 0 2022-11-24 10:45:55
3 02d7938e06934f48b92baec5348a8609 yanwenyi ... 0 2020-07-30 16:20:25
4 0311e42abab4467a80aefd2ebd18ab19 zhangjifang ... 0 2020-07-30 16:20:25
.. ... ... ... ... ...
64 9ca276a5609111edabb4204747cf5c3e HuYujiao ... 0 2022-11-10 08:50:39
65 9ca87e7a609111edabb4204747cf5c3e TaoHan ... 0 2022-11-10 08:50:39
66 9ef1c745625d11edbffa005056c00001 wxl ... 0 2022-11-14 21:45:40
67 d6ae0dd2633c11ed9d3d00ffac55512a wec ... 0 2022-11-14 21:43:09
68 fb1b7efc853b40d0b2206d8a1c672d53 eee ... 0 2022-11-17 16:02:18
[69 rows x 10 columns]
进程已结束,退出代码为 0
标签:11,...,SQLAlchemy,16,2022,MYSQL,supports,pandas From: https://www.cnblogs.com/shanchahuaya-2001/p/18143736