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)