ERROR 1045 - A big problem with the access to my mysql db

382 views Asked by At

I was trying to execute "python manage.py migrate" in my project directory made in django. The output was:

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

So, I thought that I was having a problem with the db password of root user, I saw toturials to change the password, then, I try to enter with "mysql -u root -p" and it tried to enter but it did not accept, it said it was invalid. I tried "sudo" and if it worked, I changed the password and everything was fine. but when I try to migrate data I still have same dilemma.

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

I assumed that I had to see that I could only do it with "sudo", the question is that I needed to use the data for my project to make use of them

auth': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'api_db_project',
        'USER': 'root',
        'PASSWORD': 'PASSWORDRANDOM',
        'HOST': 'localhost',
        'PORT': 3306
    },

I thought that I had not solved the problem so I look for more guides and I find:https: //stackoverflow.com/questions/39281594/error-1698-28000-access-denied-for-user-rootlocalhost

$ sudo mysql -u root # I had to use "sudo" since is new installation

mysql> USE mysql;
mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> exit;

$ service mysql restart

So when I try to test it still doesn't work, I see more guides and when I try to enter mysql to test more things, I can't even enter with "sudo", no password works and I don't know what to do at this point. This prints:

mysql: [ERROR] Found option without preceding group in config file /etc/mysql/mysql.conf.d/mysql.cnf at line 6.
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

Does anyone know what happened? I am new in this :(

Here I leave some info

cat /etc/mysql/mysql.conf.d/mysql.cnf 
#
# The MySQL database client configuration file
#
# Ref to https://dev.mysql.com/doc/refman/en/mysql-command-options.html

blind-address   = 127.0.0.1
blind-address   = *
blind-address   = *
blind-address   = 0.0.0.0

[mysql]

Ubuntu 20.04 mysql Ver 8.0.21-0ubuntu0.20.04.4 Django 2.2.2

1

There are 1 answers

1
林敬智 On

I am not sure why you can't login. On a ubuntu 20.04 with MariaDB I just do

sudo mariadb
GRANT ALL ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;

Maybe you can try this on yours. By default the root account is for login without password I think.