Yes, this is a common question in Stack Overflow but my problem is kinda different!
I have a server on Digital Ocean . Os: Ubuntu 18.04
I was trying to host my django project on the apache server with mysql .
I have completed the first part but the problem is integrating the mysql . I have installed the mysql and mysqlclient . There is a user root with password in my mysql . I have created a database and gave the following permission.
GRANT ALL PRIVILEGES ON urp_test.* TO 'root'@'localhost' identified by 'password_for_root';
The I configured my settings.py file. Here is the db portion:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'urp_test',
'USER': 'root',
'PASSWORD': 'password_for_the_db',
'HOST': 'localhost',
'PORT': '3306',
}
}
Then I did a python manage.py makemigrations
, python manage.py migrate
, python manage.py createsuperuser
.
All of them were executed successfully. So when I go login from the admin module, I see the error:
OperationalError at /admin/login/ (1698, "Access denied for user 'root'@'localhost'")
I tried deleting the database and doing the same thing a couple of times but the same problem.
Edit :
If I log in with the same user and password from terminal , ie like this:
mysql -u root -p
with the password, I can access the databases.
As I mentioned earlier, python manage.py createsuperuser
does create a user and I can get the user from the database table.
The problem is when I try to log in that user from the admin
part from the browser ie like this:
WXYZ:80/admin/login
I got the mentioned error. Here WXYZ
is the IP for my DigitalOcean server
So, it's definitely a permission error still, isn't it?
There are some complications to opening a db
under root
user. You can see details here
What I did:
logged in as root user in mysql
mysql> mysql -u root -p
created a new user
mysql> CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
mysql> FLUSH PRIVILEGES;
mysql> exit
Then I logged in as new user
mysql -u newuser -p
and enetered the new password
I set up earlier to create this user.
Then I created the db
by
create database my_database_name
我遇到了同样的问题,我只是在 settings.py 中将我的主机从 127.0.0.1 更改为 localhost,现在在我的 vps 上运行良好。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.