Reputation: 185
when I used command "python manage.py makemigrations"(the same with typing "python manage.py runserver"),it threw this error.And then I checked the authority of the users. The code and result are as fllows.
mysql> select host,user from mysql.user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| % | root |
| % | zhuxin |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
| localhost | zhuxin |
+-----------+---------------+
mysql> show grants for 'zhuxin'@'%';
+---------------------------------------------------------------+
| Grants for zhuxin@% |
+---------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'zhuxin'@'%' WITH GRANT OPTION |
| GRANT ALL PRIVILEGES ON `blogdb`.* TO 'zhuxin'@'%' |
+---------------------------------------------------------------+
mysql> show grants for 'root'@'%';
+--------------------------------------------------+
| Grants for root@% |
+--------------------------------------------------+
| GRANT USAGE ON *.* TO 'root'@'%' |
| GRANT ALL PRIVILEGES ON `blogdb`.* TO 'root'@'%' |
+--------------------------------------------------+
I have tried everything to solve it, but for no use.
Upvotes: 17
Views: 54259
Reputation: 352
In My case I was using the wrong port number, I have configured the MySql on 3307 and was using 3306 in the settings.py
file
DATABASES = {
"default": {
"ENGINE": "django.db.backends.mysql",
"NAME": "reservations",
"HOST": "127.0.0.1",
"PORT": "3307",
"USER": "root",
}
}
Upvotes: 0
Reputation: 1
I accidentally used USERNAME:
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'inventory',
'HOST': '127.0.0.1',
'USERNAME': 'root',
'PORT': '',
'PASSWORD': '', # Your Password
}
Just change it to USER
Upvotes: 0
Reputation: 1
I had the same problem and I learn from linuxnightly.com that it is caused by auth socket plugin, once you disable it the problem is solved.
Try running the following commands after you are logged into mysql as root:
mysql> USE mysql;
mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password_here';
mysql> exit;
$ sudo systemctl restart mysql
To make this work, you have to change root's password. This is done by the UPDATE
command. You have to restart mysql at the end of the process with the systemctl
command at the end.
source: https://linuxnightly.com/error-1698-28000-access-denied-for-user-rootlocalhost/
Upvotes: -1
Reputation: 217
Remove the password field if not set.
DATABASES = {
"default": {
"ENGINE": "django.db.backends.mysql",
"NAME": "reservations",
"HOST": "127.0.0.1",
"PORT": "3306",
"USER": "root",
}
}
Add this snippet of code.
Upvotes: 0
Reputation: 2847
I saw this error message after copying my project onto a new machine from a backup file. An additional error message explained the problem:
[Warning] World-writable config file '/home/myuser/myproject/database.cnf' is ignored.
The permissions of my database configuration file had been changed and it was not being loaded, therefore Django was trying to connect with the wrong user. I fixed this by running:
chmod 600 database.cnf
Upvotes: 0
Reputation: 31
I had the same error and changing the HOST
to 127.0.0.1
and removing the password worked for me. You can try it out and see if it will work for you as well.
Upvotes: 2
Reputation: 31
Check Your Database Username and Password. many time, we do typing mistake. it doesn't match from the database username and password so occur this error. I faced this error and trust me, it is my very bad experience.
Upvotes: 2
Reputation: 13047
You need to make changes in project settings.py. Provide USER
and PASSWORD
for your database
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'myproject',
'USER': 'root',
'PASSWORD': 'rootpassword',
'HOST': 'localhost',
'PORT': '',
}
}
Upvotes: 19