[英]OperationalError: (1045, “Access denied for user 'root'@'localhost' (using password: YES)”)
I use Scrapy and wnat to insert the Data in my database. 我使用Scrapy和wnat将数据插入数据库中。
in my database.py i have 在我的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()
except MySQLdb.Error as e: print "\\033[31mError %d: %s\\033[0m" % (e.args[0],e.args 1 ) MySQLdb.Error除外,例如e:打印“ \\ 033 [31mError%d:%s \\ 033 [0m”%(e.args [0],e.args 1 )
and in manager when i want to connect to mysql with 并在管理器中,当我想使用
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()
i have this error: 我有这个错误:
OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")
I read this question and this one but i have already the same eror and i can' access to my database 我读了这个问题,并且这一个 ,但我已经同eror和我不能访问我的数据库
Check if you are correctly setting the root password, but remember you can reset the password. 检查您是否正确设置了root密码,但请记住您可以重置密码。
First things first. 首先是第一件事。
Stop mysql server 停止mysql服务器
sudo /etc/init.d/mysql stop
Log in as root and stop the mysql daemon. 以root用户身份登录并停止mysql守护进程。 Now lets start up the mysql daemon and skip the grant tables which store the passwords. 现在让我们启动mysql守护程序,并跳过存储密码的授权表。
mysqld_safe --skip-grant-tables &
You should see mysqld start up successfully. 您应该看到mysqld成功启动。 If not, well you have bigger issues. 如果没有,那么您有更大的问题。 Now you should be able to connect to mysql without a password. 现在您无需密码即可连接到mysql。
mysql -u root mysql
update user set Password=PASSWORD('new-password') where user='root';
flush privileges;
exit;
had same issue ,changed connector and it worked for me, but first install the module 有同样的问题,更改了连接器,它对我有用,但是先安装模块
$ pip install mysql-connector-python $ 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.