Article From:https://www.cnblogs.com/wuheng-123/p/9688130.html
from sqlalchemy import create_engine


HOSTNAME = '127.0.0.1'

PORT = 3306

DATABASE = 'first_sqlalchemy'

USERNAME = 'root'

PASSWORD = '123456'

#dialect+driver://username:password@host:port/database
DB_URI = "mysql+pymysql://{username}:{password}@{host}:{port}/" \
"{db}?charset=utf8".format(username=USERNAME,password=PASSWORD,host=HOSTNAME,port=PORT,db=DATABASE)


engine = create_engine(DB_URI)

#Decide whether to link successfully.

conn = engine.connect() #Link successfully fetches the pointer to the operation database.

result = conn.execute('select 1')

print(result.fetchone())#Extract a result
Link of this Article: Sqlalchemy link database

Leave a Reply

Your email address will not be published. Required fields are marked *