Python爬虫访问MySQL访问失败(access denied for root@localhost((using password yes)

写python爬虫,使用pymysql连接MySQL数据库时发现以下问题:


[Running] python "c:\Users\milano\Desktop\Learning_way\Python\爬虫\sqldem.py"
Traceback (most recent call last):
  File "c:\Users\milano\Desktop\Learning_way\Python\����\sqldem.py", line 5, in <module>
    conn = pymysql.connect(host="127.0.0.1", port=3306, user='root', password='passsword', db='mysql', charset='utf8')
  File "C:\Program Files\Python36\lib\site-packages\pymysql\__init__.py", line 90, in Connect
    return Connection(*args, **kwargs)
  File "C:\Program Files\Python36\lib\site-packages\pymysql\connections.py", line 699, in __init__
    self.connect()
  File "C:\Program Files\Python36\lib\site-packages\pymysql\connections.py", line 936, in connect
    self._request_authentication()
  File "C:\Program Files\Python36\lib\site-packages\pymysql\connections.py", line 1156, in _request_authentication
    auth_packet = self._read_packet()
  File "C:\Program Files\Python36\lib\site-packages\pymysql\connections.py", line 1018, in _read_packet
    packet.check_error()
  File "C:\Program Files\Python36\lib\site-packages\pymysql\connections.py", line 384, in check_error
    err.raise_mysql_exception(self._data)
  File "C:\Program Files\Python36\lib\site-packages\pymysql\err.py", line 107, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")

google之后解决如下:


# 在mysql中使用下面这个命令登入MySQL:
mysql -uroot -p password

# 进入你项目使用的数据库
use yourdata_base

# 输入以下命令:
grant usage on *.* to 你项目使用的user@localhost identified by'你的密码';
# 例如:
grant usage on *.* to root@localhost identified by'password';
#最后输入:
FLUSH PRIVILEGES;


问题解决。

发布了26 篇原创文章 · 获赞 24 · 访问量 5万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览