问题描述
我尝试使用以下方法从Python 3.3访问MySQL:
I tried to access MySQL from Python 3.3 with the following methods:
import mysql.connector
config = {
'user': '###',
'password': '******',
'host': '##.##.#.##',
'database': '########',
'port': '####',
'raise_on_warnings': True,
}
cnx = mysql.connector.connect(**config)
cnx.close()
但是当我运行上面的代码时,出现了这个错误:
but when I ran the above code, I got this error:
mysql.connector.errors.ProgrammingError: 1045 (28000): Access denied for user '###'@'##.##.#.###' (using password: YES);
为什么会出现此错误,该如何解决?
Why am I getting this error, and how can I fix it?
推荐答案
我想为原因添加另一种可能性:MySQL和mysql-connector-python
之间的版本不匹配.当我使用MySQL 5.6.24-72.2-log
和mysql-connector-python==8.0.13
时,这个问题发生在我身上.降级为mysql-connector-python==8.0.5
解决了该问题.尽管我使用的是Python 2,但希望这会为调试提供更多线索.
I would like to add one more possibilities for the cause: version mismatch between your MySQL and mysql-connector-python
. This problem happened to me when I was using MySQL 5.6.24-72.2-log
and mysql-connector-python==8.0.13
. Downgrading to mysql-connector-python==8.0.5
resolved the issue. Though I was using Python 2, hopefully this would provide more clues for debugging.
这篇关于从Python 3访问MySQL 3:用户拒绝访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!