前言
當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")