繁体   English   中英

OperationalError:(1045,“拒绝用户'root'@'localhost'的访问(使用密码:是)”)

[英]OperationalError: (1045, “Access denied for user 'root'@'localhost' (using password: YES)”)

我使用Scrapy和wnat将数据插入数据库中。

在我的database.py中

def __init__(self, host='', user='', password='', database=''):
    self.__host     = 'localhost'
    self.__user     = 'root'
    self.__password = 'mypass'
    self.__database = 'drive'
## End def __init__

def __open(self):
    try:
cnx = MySQLdb.connect(self.__host, self.__user, self.__password, self.__database, port="3308")
self.__connection = cnx
self.__session    = cnx.cursor()

MySQLdb.Error除外,例如e:打印“ \\ 033 [31mError%d:%s \\ 033 [0m”%(e.args [0],e.args 1

并在管理器中,当我想使用

    self.mysql = MysqlPython(self.host, self.user, self.password, self.db)
    self.connection = MySQLdb.connect(self.host, self.user, self.password, self.db)
    self.cursor = self.connection.cursor()

我有这个错误:

OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")

我读了这个问题,并且这一个 ,但我已经同eror和我不能访问我的数据库

在此处输入图片说明

检查您是否正确设置了root密码,但请记住您可以重置密码。

首先是第一件事。

停止mysql服务器

sudo /etc/init.d/mysql stop

以root用户身份登录并停止mysql守护进程。 现在让我们启动mysql守护程序,并跳过存储密码的授权表。

mysqld_safe --skip-grant-tables &

您应该看到mysqld成功启动。 如果没有,那么您有更大的问题。 现在您无需密码即可连接到mysql。

mysql -u root mysql

update user set Password=PASSWORD('new-password') where user='root';
flush privileges;

exit;

有同样的问题,更改了连接器,它对我有用,但是先安装模块

$ pip安装mysql-connector-python

import mysql.connector
cnx = mysql.connector.connect(user='root', password='psw', host='127.0.0.1', database='db')

尝试在末尾添加Grant Option:

GRANT all privileges on dbx.* to 'x'@'localhost' IDENTIFIED BY 'x' WITH GRANT OPTION;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MySQLdb._exceptions.OperationalError OperationalError:(1045,“用户'root'@'localhost'的访问被拒绝(使用密码:是)”) Django OperationalError,位于/(1045,“拒绝用户'root'@'localhost'的访问(使用密码:是)”) OperationalError:(1045,“拒绝用户'root'@'localhost'的访问(使用密码:NO)”) sqlalchemy.exc.OperationalError:(MySQLdb._exceptions.OperationalError)(1045,“用户'root'@'localhost'的访问被拒绝(使用密码:NO)”) Python/Masonite:pymysql.err.OperationalError(1045,“用户 'root'@'172.18.0.1' 的访问被拒绝(使用密码:YES)”) sqlalchemy.exc.OperationalError:(MySQLdb._exceptions.OperationalError)(1045,“用户'taran'@'localhost'的访问被拒绝(使用密码:是)”) django.db.utils.OperationalError: (1045: Access denied for user 'root'@'localhost' (using password: NO) 无法在Google CloudSQL OperationalError 1045上运行syncdb,使用密码:用户'root'@'localhost'拒绝访问 OperationalError: (1045, “用户 'rajendra'@'localhost' 的访问被拒绝(使用密码:NO)”) 带有mysql和django的Travis CI返回(1045,“拒绝用户'root'@'localhost'的访问(使用密码:是)”)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM