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)
#判断是否链接成功
conn = engine.connect() #链接成功获取操作数据库的指针
result = conn.execute('select 1')
print(result.fetchone())#提取一条结果