我尝试使用以下方法从 Python 3.3 访问 MySQL:
import mysql.connector
config = {
'user': '###',
'password': '******',
'host': '##.##.#.##',
'database': '########',
'port': '####',
'raise_on_warnings': True,
}
cnx = mysql.connector.connect(**config)
cnx.close()
但是当我运行上面的代码时,出现了这个错误:
mysql.connector.errors.ProgrammingError: 1045 (28000): Access denied for user '###'@'##.##.#.###' (using password: YES);
为什么会出现此错误,我该如何解决?
原文由 Leo Sun 发布,翻译遵循 CC BY-SA 4.0 许可协议
我想为原因添加另一种可能性:您的 MySQL 和
mysql-connector-python
之间的版本不匹配。当我使用 MySQL5.6.24-72.2-log
和mysql-connector-python==8.0.13
时,这个问题发生在我身上。降级到mysql-connector-python==8.0.5
解决了这个问题。虽然我使用的是 Python 2,但希望这会为调试提供更多线索。