pandas连接mysql数据库
- 游戏开发
- 2025-08-29 07:30:02

# pandas连接mysql数据库 # 1.安装依赖 “UserWarning: pandas only supports SQLAlchemy connectable (engine/connection) or database string URI or sqlite3 DBAPI2 connection. Other # DBAPI2 objects are not tested. Please consider using SQLAlchemy.” conda install sqlalchemy pymysql # 2.导入类库 from sqlalchemy import create_engine import pandas as pd
# 3.创建数据库连接字符串 user = 'root' password = '123456' host = '127.0.0.1' port = '3306' database = 'lrcore_cloud_xxx' db_url = f'mysql+pymysql://{user}:{password}@{host}:{port}/{database}'
# 4.创建 SQLAlchemy 引擎 engine = create_engine(db_url)
# 5.使用 Pandas 读取数据 df = pd.read_sql_table('user', engine)
print(df)
''' 输出结果 id name 0 1 jack 1 2 boom 2 3 lucy 3 4 jack 4 5 boom 5 6 lucy
'''
pandas连接mysql数据库由讯客互联游戏开发栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“pandas连接mysql数据库”