pyMysql.err.OperationalError: (1045, “Access denied for user ‘root’@‘localhost’ (using password: YES
pyMysql.err.OperationalError:
(1045, “Access denied for user ‘root’@‘localhost’ (using password: YES)”)
远程连接虚拟机,部署python实现的自动排课,其中涉及到利用pymysq访问数据库、向数据库中存储数据等操作。
import pymysql# 连接数据库,参数分别为:IP地址、账号、密码、端口号、数据库名称conn = pymysql.connect(host=‘192.168.216.127’,user='root',passwd='123',port=3306,database='db1')
pymysql.err.OperationalError: (1045, “Access denied for user ‘root’@‘192.168.216.127’ (using passWord: YES)”)
1.用户授权
打开命令行,输入mysql -u root -p,在Enter password:后面输入密码,如下图所示:
在mysql后面输入以下代码:
GRANT ALL PRIVILEGES ON . TO ‘myuser’@’%’ IDENTIFIED BY ‘mypassword’ WITH GRANT OPTION;# 其中,myuser为账号,mypassword为密码FLUSH PRIVILEGES;
2.修改IP地址的格式
把host=‘192.168.216.127’ 修改成host=‘localhost’,如下所示
conn = pymysql.connect(host=‘localhost’,user='root',passwd='123',port=3306,database='db1')
来源地址:https://blog.csdn.net/weixin_42586726/article/details/127051326
--结束END--
本文标题: pymysql报1045错误
本文链接: https://lsjlt.com/news/399453.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0