#安装完毕有关模块后 import pandas as pd from sqlalchemy import create_engine # 初始化数据库连接,使用pymysql模块 import pandas as pd from sqlalchemy import create_engine engine = create_engine("mysql+pymysql://{}:{}@{}/{}?charset={}".format('root','1234', '127.0.0.1','mysql','utf8')) # 初始化数据库连接,使用pymysql模块 # engine = create_engine("mysql+pymysql://{}:{}@{}/{}?charset={}" # .format('用户名', # '密码', # 'ip地址:端口号', # '数据库名称', # 'utf8') # ) sql1 = '''select * from mysql limit 5''' df = pd.read_sql_query(sql1, engine) print(df) sql2 = '''select * from mysql limit 20''' df = pd.read_sql_query(sql2,engine) print(df)
SQLalchemy读取MySQL
最新推荐文章于 2024-10-26 12:02:06 发布