sqlalchemy和pymysql连接mysql的方法
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sqlalchemy和pymysql连接mysql的方法相关的知识,希望对你有一定的参考价值。
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:[email protected]:3306/class",encoding='utf-8', echo=False) engine = create_engine("mysql+pymysql://%s:%[email protected]%s:%s/class" %(mysql_user,mysql_pw,mysql_host,mysql_port),encoding='utf-8', echo=False) Base = declarative_base()
以上是关于sqlalchemy和pymysql连接mysql的方法的主要内容,如果未能解决你的问题,请参考以下文章
sqlalchemy 使用pymysql连接mysql 1366错误
sqlalchemy 使用pymysql连接mysql 1366错误
python操作mysql(pymysql + sqlalchemy)