Python连接mysql或postgres(sqlalchemy)
安装 sudo pip install sqlalchemy 或sudo pip3 install sqlalchemy 下载速度慢可使用国内源,如: sudo pip install sqlalchemy -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com 测试1 from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker eng = create_engine('mysql+mysqlconnector://y-user:y-passwd@127.0.0.1:3306/y-db?charset=utf8') #eng = create_engine('postgresql+psycopg2://y-user:y-passwd@127.0.0.1:5432/y-db',echo=True,client_encoding='utf8') DB_Session = sessionmaker(bind=eng) session = DB_Session() data = session.execute("SELECT * FROM y-table") for row in data: for