SQLAlchemy and Pymysql ways to connect to MySQL

Source: Internet
Author: User

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 and Pymysql ways to connect to MySQL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.