视频直播系统源码,sqlalchemy的数据库连接与验证
视频直播系统源码,sqlalchemy的数据库连接与验证
安装pymysql
pip install pymysql
安装sqlalchemy
pip install sqlalchemy
连接数据库
'''
this is sqlalchemy
'''
from sqlalchemy import create_engine
HOSTNAME = '192.168.31.105'
PORT = '3306'
DATABASE = 'mydb'
USERNAME = 'admin'
PASSWORD = 'Root110qwe'
db_url = 'mysql+pymysql://{}:{}:@{}/{}?charset=utf8'.format(
USERNAME,
PASSWORD,
HOSTNAME,
DATABASE,
)
engine = create_engine(db_url)
#创建对象
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base(engine)
#创建会话 增删改查
from sqlalchemy.orm import sessionmaker
Session = sessionmaker(engine)
session = Session()
if __name__=='__main__':
print(dir(engine))
print('----Base----:',dir(Base))
print('----Session----:',dir(Session))
以上就是 视频直播系统源码,sqlalchemy的数据库连接与验证,更多内容欢迎关注之后的文章