31👍
Your user does not have an access to database. Use the commands below to set up your database.
DROP DATABASE IF EXISTS `mydb`;
CREATE DATABASE `mydb`
DEFAULT CHARACTER SET utf8
DEFAULT COLLATE utf8_general_ci;
USE 'mysql';
GRANT ALL PRIVILEGES ON mydb.* TO 'mydb_user'@'localhost' IDENTIFIED BY 'your_password'
WITH GRANT OPTION;
FLUSH PRIVILEGES;
Also, you need to have enough privileges to run it. Save it as script.sql then,
$mysql -u root -p < script.sql
Than on to settings.py where you need to make sure your db settings are set up properly
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'mydb',
'USER': 'mydb_user',
'PASSWORD': 'your_password',
'HOST': '',
'PORT': '',
}
}
and
python manage.py syncdb
and you’re done.
4👍
I also ran into this problem while following the Django tutorial on testing (https://docs.djangoproject.com/en/dev/intro/tutorial05/). When trying to test the polls app, I received the following error:
user@host:~/django/mysite$ python manage.py test polls
Creating test database for alias 'default'...
Got an error creating the test database: (1044, "Access denied for user 'admin'@'localhost' to database 'test_django_mysite'")
Type 'yes' if you would like to try deleting the test database 'test_django_mysite', or 'no' to cancel:
The problem is that django is creating a temporary database called test_django_mysite.
I was able to solve this problem by granting access to ‘admin’@’localhost’ on the test_django_mysite database that it was trying to create.
mysql> GRANT ALL PRIVILEGES ON test_django_mysite.* TO admin@localhost IDENTIFIED BY 'mypassword';
Query OK, 0 rows affected (0.04 sec)
It’s worth noting that I only granted the privileges to test_django_mysite. I didn’t need to actually create it.
- [Django]-What is choice_set in this Django app tutorial?
- [Django]-Django: invalid literal for int() with base 10
- [Django]-Why load staticfiles for every template even if it is extended?
0👍
The django book is fairly old by now. in particular, database settings are now a dictionary, rather then the bunch of variables described in the django book.
looking at the last line of your traceback, it looks like it’s trying connect without a username.
try changing
DATABASE_ENGINE = ''
DATABASE_NAME = ''
DATABASE_USER = ''
DATABASE_PASSWORD = ''
to
DATABASES = {
'default': {
'ENGINE': '',
'NAME': ''
'USER': ''
# etc
}
}
- [Django]-Django – Get only date from datetime.strptime
- [Django]-How to go from django image field to PIL image and back?
- [Django]-Django query case-insensitive list match
0👍
If you changed the database password and updated settings.py, you will also have to restart the wsgi.py process, for example by restarting apache.
- [Django]-Deploying Django with gunicorn and nginx
- [Django]-Link in django admin to foreign key object
- [Django]-Limiting Memory Use in a *Large* Django QuerySet
0👍
My problem was that I was editing settings.py whereas configuration should have been done in local_settings.py
Now everything seems to work.
- [Django]-Collectstatic error while deploying Django app to Heroku
- [Django]-What is a good value for CONN_MAX_AGE in Django?
- [Django]-How to fix " AttributeError at /api/doc 'AutoSchema' object has no attribute 'get_link' " error in Django
0👍
I had a similar problem and yet all settings seemed correct. I later noticed MySQL was using port 3308 and yet I had port 3306 in my Django settings file. I updated the settings file to resolve the issue.
- [Django]-Embed YouTube video – Refused to display in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'
- [Django]-How do I perform HTML decoding/encoding using Python/Django?
- [Django]-Uncaught TypeError: Cannot read property 'ownerDocument' of undefined
-1👍
Just gonna leave my answer here because I lost few good minutes (almost hour) on this matter.
Watch Your copy-paste 🙂 Unfortunately, mysql return success while granting priviliges for not existing user to not existing database…
Both queries:
GRANT ALL PRIVILEGES ON python_user.* TO 'python_db'@'%' WITH GRANT OPTION;
and:
GRANT ALL PRIVILEGES ON python_db.* TO 'python_user'@'%' WITH GRANT OPTION
will return success. Aldo I don’t have such a user called python_db and db named python_user. 🙂 That’s sad. My mistake but also MySql was not helpful enough with output. 🙂
- [Django]-Django dynamically filtering with q objects
- [Django]-How to reverse the URL of a ViewSet's custom action in django restframework
- [Django]-How can i use signals in django bulk create
-1👍
You need to verify database configurations in settings.py file and also if your db user has privilege to access the database and perform operations on it.
Please see if solutions mentioned here works for you.
- [Django]-Auth.User.groups: (fields.E304) Reverse accessor for 'User.groups' clashes with reverse accessor for 'UserManage.groups'
- [Django]-Configure Django and Google Cloud Storage?
- [Django]-How to add the current query string to an URL in a Django template?