from sqlalchemy import create_engine from urllib.parse import quote_plus # 老版本python解释器通用 format # mysql_dict = dict( # host="127.0.0.1", # port=3306, # name="chatroom_project", # user="root", # pwd="XXX@123456" # ) # link = "mysql+mysqlconnector://{user}:{pwd}@{host}:{port}/{name}".format(**mysql_dict) host = "127.0.0.1" port = 3306 name = "chatroom_project" user = "root" pwd = "XXX@123456" link = f"mysql+mysqlconnector://{user}:{quote_plus(pwd)}@{host}:{port}/{name}" engine = create_engine( link, encoding="utf-8", echo=True # 是否输出日志 ) metadata.create_all(engine)
这里问题是 使用这个链接由py文件生成库表时,我的密码中包含了特别字符导致解析错误,
所以使用from urllib.parse import quote_plus 这个模块来加密下我的密码,问题就解决了