0

Following a tutorial on youtube on how to set up and use the DjangoFramework. Tried running python manage.py migrate but I ran into this error and I'm unable to figure out a solution to it. Using mysqlclient and running on a virtual environment and on MACOS

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

I don't know if this would be the issue, but I created a database on using the myphpadmin on http://localhost:8080/phpmyadmin/. localhost/phpmyadmin does not work.

The code for DATABASES in settings.py is as follows :

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'djangoproject',
        'USER' :  'root',
        'PASSWORD' : 'rootpassword',
        'HOST': 'localhost',
        'PORT' : '' ,
    }
}
theBuzzyCoder
  • 2,652
  • 2
  • 31
  • 26
Zepha
  • 19
  • 3

1 Answers1

1

If you are connecting with phpmyadmin by default no password set. And also write port number.

DATABASES = {
'default': {
 'ENGINE': 'django.db.backends.mysql',
 'NAME': 'djangoproject',
 'USER' :  'root',
 'PASSWORD' : '',
 'HOST': 'localhost',
 'PORT' : '3306' ,
}

Change password of phpmyadmin

  • Tried this. Gave me the same error with (using password :NO) instead – Zepha Nov 13 '18 at 16:59
  • @bernardang go to phpmyadmin dashboard click the User accounts tab then check User name 'root' and Host 'localhost' then Edit privileges of this account. Then change password of this account. – Muhammad Faizan Fareed Nov 13 '18 at 17:17
  • Was I supposed to change it to what I put it as in the DATABASES code ?I did that and now I am getting Access Denied error. "phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server." – Zepha Nov 13 '18 at 17:30
  • I have actually gotten it to work. by changing the settings on XAMPP. However, I still cant get phpmyadmin to work on localhost/phpmyadmin or localhost:8000/phpmyadmin where the server on my django app is run on.Any fix to this? – Zepha Nov 13 '18 at 17:54
  • [Access denied error solution. ](https://stackoverflow.com/questions/19482371/fix-access-denied-for-user-rootlocalhost-for-phpmyadmin) – Muhammad Faizan Fareed Nov 13 '18 at 17:57
  • When you run your server it give you server running link. Starting development server at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK. And phpmyadmin link is http://localhost/phpmyadmin/ – Muhammad Faizan Fareed Nov 13 '18 at 17:59
  • localhost/phpmyadmin returns me : This site can be reached. localhost refused to connect. – Zepha Nov 13 '18 at 19:20
  • @bernardang Apache and MySQL is running correctly ? – Muhammad Faizan Fareed Nov 13 '18 at 19:26
  • Yes it is. At least it shows that it's green on the XAMPP. Anyway, I am back to my previous issue. I realized that I ran the migration with the default sqlite3 provided by django that's why it worked. I am still unable to run python manage.py migrate with the mysql. I am still getting the same error. I have a feeling this has something to do with XAMPP being on a different port than my Django server. – Zepha Nov 13 '18 at 19:37