- [图数据库: dgraph](dgraph - Graph DB.md)
- Note of db data - MongoDB
- Note of db data - MySQL
URL连接 #
URL特殊字符转义 #
在构建数据库连接字符串时,URL中的某些字符具有特殊含义,如果它们出现在用户名或密码中,则需要被转义。以下是需要转义的字符及其对应的URL编码:
空格:%20!:%21":%22#:%23$:%24%:%25&:%26':%27(:%28):%29*:%2A+:%2B,:%2C/:%2F::%3A;:%3B<:%3C=:%3D>:%3E?:%3F@:%40[:%5B\:%5C]:%5D^:%5E_:%5F`(空格):%60{:%7B|:%7C}:%7D~:%7E
示例 #
假设密码是 hihi#wav12391176393,其中包含特殊字符 #,我们需要将其转义。
from urllib.parse import quote_plus
password = "hihi#wav12391176393"
encoded_password = quote_plus(password)
URL = f'mysql://root:{encoded_password}@127.0.0.1:3306/installer'