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

时间:2016-05-30 15:04:10

标签: python mysql xampp scrapy mysql-error-1045

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

在我的database.py中有

www.blablabla.com.ar.   CNAME   300 blablabla.com.ar.

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

并且在管理器中我想用

连接到mysql
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()

我有这个错误:

    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()

我读了这个questionthis one,但我已经有了同样的错误,我可以“访问我的数据库”

enter image description here

3 个答案:

答案 0 :(得分:2)

检查您是否正确设置了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;

答案 1 :(得分:2)

  

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

$ pip install mysql-connector-python

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

答案 2 :(得分:0)

尝试在最后添加Grant Option:

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