前言
当MySQL密码中含有特殊字符时,使用sqlalchemy大概率连不上,这时候就需要from urllib.parse import quote_plus as urlquote
。
示例代码
from sqlalchemy import create_engine
from urllib.parse import quote_plus as urlquote
mysql_password = "!@#$%^&*()"
eng = create_engine(f"mysql+pymysql://myuser:{urlquote(mysql_password)}@127.0.0.1:3306/dbtest")