一、sqlalchemy原生语句操作
from sqlalchemy import create_engine HOSTNAME = '127.0.0.1' PORT = 3306 DATABASE = 'demo' USERNAME = 'root' PASSWORD = '123456' # 链接数据库的字符串,固定格式 DB_URL = "mysql+pymysql://{username}:{password}@{host}:{port}/{db}?charset=utf8".format( username = USERNAME, password = PASSWORD, host = HOSTNAME, port = PORT, db = DATABASE, ) engine = create_engine(DB_URL) # 判断是否链接成功 conn = engine.connect() result = conn.execute('SELECT * FROM shop_area') print(result.fetchone())