sqlalchemy操作mysql

from sqlalchemy import Column,String,create_engine,MetaData
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
import pymysql
Base=declarative_base()
meta=MetaData()

class User(Base):
    __tablename__=‘BUMEN‘
    
    id=Column(String(20),primary_key=True)
    name=Column(String(20))
    
engine=create_engine("mysql+pymysql://root:root@localhost:3306/haiku")
DBSession=sessionmaker(bind=engine)
session=DBSession()
User.metadata.create_all(bind=engine)
new_user=User(id=‘5‘,name=‘maker‘)
session.add(new_user)
session.commit()
session.close()

sqlalchemy操作mysql

上一篇:1.Mysql之MHA高可用(01)


下一篇:SQL -4