尝试执行使用 MySQL 的 Python 程序时出错

发布于 2024-10-31 08:44:35 字数 739 浏览 5 评论 0原文

我有一个使用 MySQL 数据库的 python 程序。
我收到以下错误。
如果有人帮助我找到解决方案,我将不胜感激。

Traceback (most recent call last):
File "version2_1.py", line 105, in 
refine(wr,w)#function for replacement
File "version2_1.py", line 49, in refine
wrds=db_connect.database(word)
File "/home/anusha/db_connect.py", line 6, in database
db = MySQLdb.connect("localhost","root","localhost","anusha" )
File "/usr/lib/pymodules/python2.6/MySQLdb/_init_.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line 170, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")

I have a python program which makes use of MySQL database.
I am getting following error.
It would be very grateful if some one help me out a solution.

Traceback (most recent call last):
File "version2_1.py", line 105, in 
refine(wr,w)#function for replacement
File "version2_1.py", line 49, in refine
wrds=db_connect.database(word)
File "/home/anusha/db_connect.py", line 6, in database
db = MySQLdb.connect("localhost","root","localhost","anusha" )
File "/usr/lib/pymodules/python2.6/MySQLdb/_init_.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line 170, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")

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

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

发布评论

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

评论(3

夏日落 2024-11-07 08:44:35

您需要阅读 MySQL 中的权限和安全性。查看这些链接:

可能是您的用户不允许完全连接,或者只允许某些类型的查询。可能是您的远程主机不允许连接到 MySQL 服务器。在为 MySQL 用户建立授权时应考虑所有这些因素。

You need to read about permissions and security within MySQL. Have a look at these links:

It could be that your user is not allowed to connect at all, or that it is only allowed certain types of queries. It could be that your remote host is not allowed to connect to the MySQL server. All of these considerations should be made when establishing grants for MySQL users.

北方的韩爷 2024-11-07 08:44:35

在控制台中运行此命令

mysql> grant all privileges on *.* to 'user'@localhost identified by 'password' with grant option;

run this command in console

mysql> grant all privileges on *.* to 'user'@localhost identified by 'password' with grant option;
嘿嘿嘿 2024-11-07 08:44:35

您的 MySQL 用户名/密码似乎不正确。尝试在 MySQL 中创建一个用户并使用它进行连接。

Looks like you have an incorrect username/password for MySQL. Try creating a user in MySQL and use that to connect.

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