import sqlalchemy from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Column, Integer, String, ForeignKey, UniqueConstraint, Index,DATE from sqlalchemy.orm import sessionmaker, relationship from sqlalchemy import create_engine,text import datetime, pymysql,hashlib,getpass,re from core import setting hash = hashlib.md5() hash.update('123456'.encode()) default_pw=hash.hexdigest() mysql_user = setting.mysql_user mysql_pw = setting.mysql_pw mysql_host = setting.mysql_host mysql_port = setting.mysql_port # conn = pymysql.connect(host='192.168.153.132',port=3306,user='root',passwd='mysql',db='class') conn = pymysql.connect(host=mysql_host,port=mysql_port,user=mysql_user,passwd=mysql_pw,db='class') cursor = conn.cursor() # engine = create_engine("mysql+pymysql://root:mysql@192.168.153.132:3306/class",encoding='utf-8', echo=False) engine = create_engine("mysql+pymysql://%s:%s@%s:%s/class" %(mysql_user,mysql_pw,mysql_host,mysql_port),encoding='utf-8', echo=False) Base = declarative_base()
sqlalchemy和pymysql连接mysql的方法
原创w411639146 ©著作权
©著作权归作者所有:来自51CTO博客作者w411639146的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:基于rpc的主机管理程序分析
![](https://ucenter.51cto.com/images/noavatar_middle.gif)
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章