MySQLdb._exceptions.OperationalError

来源:4-19 pipeline数据库保存

慕娘7402538

2020-04-04

老师您好,入库的时候报错这一行self.conn = MySQLdb.connect(‘127.0.0.1’, ‘root’, ‘root’, ‘article_spider’, charset=“utf8”, use_unicode=True)原因是MySQLdb._exceptions.OperationalError: (1045, “Access denied for user ‘root’@‘localhost’ (using password: YES)”),我安装了mysql8.0,是不是版本的问题

整个报错:
2020-04-04 21:30:04 [twisted] CRITICAL:
Traceback (most recent call last):
File “C:\Users\Mr JIE\AppData\Local\Programs\Python\Python37\lib\site-packages\twisted\internet\defer.py”, line 1418, in _inlineCallbacks
result = g.send(result)
File “C:\Users\Mr JIE\AppData\Local\Programs\Python\Python37\lib\site-packages\scrapy\crawler.py”, line 89, in crawl
self.engine = self._create_engine()
File “C:\Users\Mr JIE\AppData\Local\Programs\Python\Python37\lib\site-packages\scrapy\crawler.py”, line 103, in _create_engine
return ExecutionEngine(self, lambda : self.stop())
File “C:\Users\Mr JIE\AppData\Local\Programs\Python\Python37\lib\site-packages\scrapy\core\engine.py”, line 70, in init
self.scraper = Scraper(crawler)
File “C:\Users\Mr JIE\AppData\Local\Programs\Python\Python37\lib\site-packages\scrapy\core\scraper.py”, line 71, in init
self.itemproc = itemproc_cls.from_crawler(crawler)
File “C:\Users\Mr JIE\AppData\Local\Programs\Python\Python37\lib\site-packages\scrapy\middleware.py”, line 53, in from_crawler
return cls.from_settings(crawler.settings, crawler)
File “C:\Users\Mr JIE\AppData\Local\Programs\Python\Python37\lib\site-packages\scrapy\middleware.py”, line 35, in from_settings
mw = create_instance(mwcls, settings, crawler)
File “C:\Users\Mr JIE\AppData\Local\Programs\Python\Python37\lib\site-packages\scrapy\utils\misc.py”, line 150, in create_instance
return objcls(*args, **kwargs)
File “C:\Users\Mr JIE\ArticleSpider\ArticleSpider\pipelines.py”, line 62, in init
self.conn = MySQLdb.connect(‘127.0.0.1’, ‘root’, ‘root’, ‘article_spider’, charset=“utf8”, use_unicode=True)
File "C:\Users\Mr JIE\AppData\Local\Programs\Python\Python37\lib\site-packages\MySQLdb_init
.py", line 84, in Connect
return Connection(*args, **kwargs)
File “C:\Users\Mr JIE\AppData\Local\Programs\Python\Python37\lib\site-packages\MySQLdb\connections.py”, line 179, in init
super(Connection, self).init(*args, **kwargs2)
MySQLdb._exceptions.OperationalError: (1045, “Access denied for user ‘root’@‘localhost’ (using password: YES)”)

写回答

2回答

夜色小闪

2021-07-22

我把 MySQLdb.connect(‘127.0.0.1’, ‘root’, ‘root’, ‘article_spider’, charset=“utf8”, use_unicode=True)

改成

MySQLdb.connect("localhost", 'root', '123456', 'article_spider', charset="utf8", use_unicode=True)

就解决了

1
1
bobby
好的。
2021-07-23
共1条回复

bobby

2020-04-05

这个报错来看是用户名密码错误了 你的用户名密码能使用navicat登录吗?

0
2
bobby
回复
慕娘7402538
mysql是免费的 navicat是收费的,不过可以免费试用 可以尝试一下 mysql本身也自带了一个管理器 不过我没怎么用过 包括pycharm本身也是可以直接管理mysql做数据管理的 使用工具是最好的测试方法
2020-04-07
共2条回复

Scrapy打造搜索引擎 畅销4年的Python分布式爬虫课

带你彻底掌握Scrapy,用Django+Elasticsearch搭建搜索引擎

5795 学习 · 6290 问题

查看课程