码迷,mamicode.com
首页 > 数据库 > 详细

sqlalchemy和pymysql连接mysql的方法

时间:2017-11-29 14:42:40      阅读:413      评论:0      收藏:0      [点我收藏+]

标签:python

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的方法

标签:python

原文地址:http://blog.51cto.com/bujuhandong/2045622

(1)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!