標籤:python
import sqlalchemyfrom sqlalchemy.ext.declarative import declarative_basefrom sqlalchemy import Column, Integer, String, ForeignKey, UniqueConstraint, Index,DATEfrom sqlalchemy.orm import sessionmaker, relationshipfrom sqlalchemy import create_engine,textimport datetime, pymysql,hashlib,getpass,refrom core import settinghash = hashlib.md5()hash.update('123456'.encode())default_pw=hash.hexdigest()mysql_user = setting.mysql_usermysql_pw = setting.mysql_pwmysql_host = setting.mysql_hostmysql_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的方法