标签:代码 sem maker style bin 查看 mariadb python html
1. 数据库配置.
https://www.cnblogs.com/mengbin0546/p/10124560.html
2. python端操作.
一、 代码:
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Column, Integer, String from sqlalchemy.orm import sessionmaker from sqlalchemy import create_engine engine = create_engine("mysql+pymysql://root:123456@132.232.xxx.XXX:3306/db1", max_overflow=5) DBSession = sessionmaker(bind=engine) session = DBSession() BaseModle = declarative_base() class User(BaseModle): __tablename__ = ‘users‘ id = Column(Integer, primary_key=True) name = Column(String(50)) class Session(BaseModle): __tablename__ = "session" id = Column(Integer, primary_key=True) user = Column(String(10), index=True) ip = Column(String(10)) # 寻找Base的所有子类,按照子类的结构在数据库中生成对应的数据表信息 BaseModle.metadata.create_all(engine) session.commit() #提交
执行后在数据库中查看:
MariaDB [db1]> show tables; +---------------+ | Tables_in_db1 | +---------------+ | mengbin | | session | | users | +---------------+ 3 rows in set (0.00 sec)
标签:代码 sem maker style bin 查看 mariadb python html
原文地址:https://www.cnblogs.com/mengbin0546/p/10145481.html