- 此问题在此处已有答案**:
Writing a connection string when password contains special characters(2个答案)
两年前关闭了。
I have been searching SO and the web for days trying to solve this issue. There are plenty of similar questions on SO but none of them seem to be the same issue that I am dealing with currently. I am trying to connect to a remote MySQL database in python to use the pandas.to_sql feature to update tables. I am able to connect with MySQL workbench without any issue. I am also able to connect using the following code:
self.conn = mysql.connector.connect(host= remote_host,user= db_user, password=db_pass)
This allows me to query the database just fine in python. However, in order to use the pandas.to_sql I need to create and engine with sqlalchemy. I have tried multiple different ports and even leaving the port off. Here is the code I have tried:
self.engine = create_engine("mysql+mysqlconnector://db_user:db_pass@remote_host:3306/db_name")
它们都给我以下错误
ProgrammingError: (mysql.connector.errors.ProgrammingError) 1045 (28000): Access denied for user 'db_user'@'c-67-176-125-82.hsd1.co.comcast.net' (using password: YES) (Background on this error at: http://sqlalche.me/e/f405)
我可以使用create_engine
连接到本地数据库,但不能连接到远程数据库。
我试过在服务器上重新启动MySQL,我已经授予用户所有权限,并刷新了服务器上的所有权限。我甚至尝试使用root用户和密码,但没有成功。
我仔细检查了用户名和密码,当然知道它们是正确的,因为它们是我在MySQL工作台中使用的,而且我只使用mysql.connector.connect
我甚至试着卸载mysql-connector-python
并重新安装。
任何帮助都将不胜感激。
1条答案
按热度按时间ecfsfe2w1#
如果数据库URL的任何组成部分可能包含可能混淆URL分析程序的特殊字符,则最好使用
sqlalchemy.engine.URL.create()
来构造URL。例如:请注意,密码中的冒号字符按百分比编码为
%3A
。