欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Python:sqlalchemy连接mysql数据库

程序员文章站 2024-03-02 19:41:10
...

python2.7:

        pip install sqlalchemy==1.4.27

        pip install mysql-connector-python-rf==2.2.2

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

engine = create_engine(
    'mysql+mysqlconnector://root:127.0.0.1:3306/test')
DBSession = sessionmaker(bind=engine)
session = DBSession()
execute_result = session.execute(
    "select * from table_A limit 1"
)
result = execute_result.fetchall()
session.close()
print(result)

相关标签: python mysql