【发布时间】:2021-02-11 10:56:22
【问题描述】:
不知何故,我的 python 应用程序无法连接到本地主机上的新 MySQL 服务器。密码好像没问题,我可以登录,但应用程序不能。
赠款:
mysql> show grants for test@localhost;
+-------------------------------------------------------------------------------+
| Grants for test@localhost |
+-------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO `test`@`localhost` |
| GRANT SELECT, INSERT, UPDATE, DELETE ON `Project`.* TO `test`@`localhost` |
+-------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
日志文件:
2021-02-11T10:49:13.897580Z 10 Connect crawler@localhost on Project using SSL/TLS
2021-02-11T10:49:13.897736Z 10 Connect Access denied for user 'test'@'localhost' (using password: YES)
但是,我可以从 CLI 连接:
$ mysql -u test -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.23 MySQL Community Server - GPL
日志文件:
2021-02-11T10:51:48.590555Z 11 Connect test@localhost on using Socket
2021-02-11T10:51:48.591527Z 11 Query select @@version_comment limit 1
密码包含以下字符串:42$7&Z,长度为 16 个字符。
我现在设置了:default_authentication_plugin= mysql_native_password ,但仍然没有变化。
来自 Python 3.8 的连接(适用于其他服务器):
def create_connection(self):
settings = get_project_settings()
self.conn = mysql.connector.connect(
host=settings.get('MYSQL_SERVER'),
user=settings.get('MYSQL_USER'),
passwd=settings.get('MYSQL_PW'),
database=settings.get('MYSQL_DB'),
charset='utf8'
)
self.conn._time_zone = '+00:00'
self.conn.autocommit = True
self.curr = self.conn.cursor()
self.curb = self.conn.cursor(buffered=True)
有什么我忽略的吗?
【问题讨论】:
-
我记得 mysql 8 与以前的版本相比,使用不同的方法来处理密码。查找有关如何更新 mysql server 8 的 pyton 代码的说明。或检查如何启用密码的兼容模式以使 mysql 使用旧方法
-
对,我记得。现在将其设置为:default_authentication_plugin= mysql_native_password 但即使在重新启动服务器后它也是相同的
-
请分享更多细节 - 您如何尝试在您的应用程序中连接?
-
我在问题中添加了部分代码。这适用于其他系统。
-
这能回答你的问题吗? Mysql localhost != 127.0.0.1?
标签: mysql