mysql-connector-python 错误 1045 (28000):使用密码的用户访问被拒绝:是

发布于 2025-01-12 04:17:37 字数 967 浏览 0 评论 0原文

我在连接 mysql/mariadb 数据库时遇到问题。我在 jupyter 实验室中收到以下错误:

ProgrammingError: 1045 (28000): Access denied for user 'xx'@'yy' (using password: YES)

这是我的代码:

    import mysql.connector as mariadb

    CONFIG_READ ={'user': 'xx', 'password': 'zz', 
'host': 'myadress', 'database': 'dbname', 'raise_on_warnings': True}  
#i'm sure the entered info here is correct
        
        def read(query, params=()):
            try:
                conn = mariadb.connect(**CONFIG_READ)
                cursor = conn.cursor()
                cursor.execute(query, params)
                result = cursor.fetchall()
            finally:
                conn.close()
            return result

我在安装了 mysql-connector-python 8.0.27 的 docker 容器中运行它。我真的很想听听您关于如何解决这个问题的建议。在堆栈上,我只能通过手动调整 pip 中的 mysql 设置来找到解决方案,这对我的情况没有帮助,因为我们需要这个特定版本的 mysql-connector-python 来连接到另一个数据库。有没有办法从 linux bash 解决这个问题?

期待您的来信。

问候, 杰罗姆

I am having trouble connecting to a mysql / mariadb database. I am getting the following error in jupyter lab:

ProgrammingError: 1045 (28000): Access denied for user 'xx'@'yy' (using password: YES)

Here is my code:

    import mysql.connector as mariadb

    CONFIG_READ ={'user': 'xx', 'password': 'zz', 
'host': 'myadress', 'database': 'dbname', 'raise_on_warnings': True}  
#i'm sure the entered info here is correct
        
        def read(query, params=()):
            try:
                conn = mariadb.connect(**CONFIG_READ)
                cursor = conn.cursor()
                cursor.execute(query, params)
                result = cursor.fetchall()
            finally:
                conn.close()
            return result

I am running this in a docker container where mysql-connector-python 8.0.27 is installed. I would really like to hear your advise on how to solve this problem. On stack I could only find solutions by manually adjusting mysql settings in pip, that didn't help in my case, since we need this specific version of mysql-connector-python to connect to another db. Is there a way to fix this from linux bash?

Looking forward to hear from you.

Greetings,
Jerome

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悟红尘 2025-01-19 04:17:37

我在 mysql.connector 上也遇到了同样的问题。使用 pymysql 模块,它的连接方式相同。只需阅读文档,因为方法参数名称可能不同!

I've had the same problem with mysql.connector. Use the pymysql module, it connects the same way. Just read the documentation because method argument names might not be the same!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文