36👍
I do it like this for a database named foo_db:
create database foo_db;
create user foo_user identified by 'foo_password';
grant all on foo_db.* to 'foo_user'@'%';
flush privileges;
11👍
In my case the settings.py has the following:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'TRYDJANGO',
'USERNAME':'user_trydjango',
'PASSWORD':'passtry',
'PORT':'3306',
'HOST': 'localhost',
}
}
And it works if I change the ‘USERNAME’ to ‘USER’:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'TRYDJANGO',
'USER':'user_trydjango',
'PASSWORD':'passtry',
'PORT':'3306',
'HOST': 'localhost',
}
}
- [Django]-How to expire session due to inactivity in Django?
- [Django]-Django ImageField change file name on upload
- [Django]-Split views.py in several files
2👍
as far as i understood someuser is a DB guest user and not the admin one, right?
If so, from your MySQL DB admin user, grant someuser to access MySQL environment table ‘mysql.user’ as follow:
GRANT SELECT ON mysql
.user
TO ‘someuser’@’%’;
To me it worked,
Ivan
- [Django]-How to use schemas in Django?
- [Django]-Django manage.py runserver invalid syntax
- [Django]-How to change help text of a django form field?
1👍
Refering to the answer of @duffymo and changed the last statement could work for me.
create database foo_db;
create user foo_user identified by 'foo_password';
grant all on foo_db.* to foo_user@localhost identified by 'foo_password' with grant option;
- [Django]-How do I return JSON without using a template in Django?
- [Django]-Docker image error: "/bin/sh: 1: [python,: not found"
- [Django]-Sending images using Http Post
1👍
My error message indicated that there wasn’t password supplied to the database:
django.db.utils.OperationalError: (1045, “Access denied for user ‘mylocalusername’@’localhost’ (using password: NO)”)
The manage.py
should pick up the database access credentials from the settings.py
, that’s a specific database user (and of course that user’s password as well). It’s a security mistake to react to my error message by granting database login privileges to the local user.
In my case there were problems with the settings.py
(we were restructuring our build pipeline from django pipeline to webpack) and I needed to remove pipeline related parts from my settings.py
for the fix. It’s a question why I didn’t get any python error message about the settings.py
problems, but instead I got this error which is not local to the real problem. That error message is just a transitive result of the source problem. Once I fixed the manage.py
, the credentials were picked up from the DATABASE settings as usual and everything went smooth.
In our case we were using django-pipeline
before webpack (more specifically pip
packages django-pipeline-browserify==0.4.1
and
django-pipeline==1.6.8
), so once we transitioned I had to just remove these lines from settings:
NODE_MODULES_BIN = '/home/myuser/sourcerepositorydir/node_modules/.bin/'
PIPELINE['SASS_BINARY'] = '/var/lib/gems/2.3.0/gems/sass-3.5.3/bin/sass'
PIPELINE['BABEL_BINARY'] = '{}{}'.format(NODE_MODULES_BIN, 'babel')
PIPELINE['BROWSERIFY_BINARY'] = '{}{}'.format(NODE_MODULES_BIN, 'browserify')
PIPELINE_BROWSERIFY_BINARY = PIPELINE['BROWSERIFY_BINARY']
PIPELINE['BROWSERIFY_ENV'] = {'NODE_ENV': 'development'}
PIPELINE['BROWSERIFY_ARGUMENTS'] = PIPELINE['BROWSERIFY_ARGUMENTS'] + ' --debug'
Until that I was just getting nonsensical error messages.
- [Django]-Giving email account a name when sending emails with Django through Google Apps
- [Django]-Django Password Generator
- [Django]-How to send email via Django?
0👍
@ mattblang:
In this case it helps if the host is set in the actually used settings.py
file too.
For me it is /etc/graphite/local_settings.py
where the DATABASES Stanzas
had a wrong value, for HOST there was:
'HOST': '127.0.0.1',
Because during the runtime of syncdb command it searched for localhost, I changed it to
'HOST': 'localhost',
Now it looks something like this:
DATABASES = {
'default': {
'NAME': 'graphite',
'ENGINE': 'django.db.backends.mysql',
'USER': 'graphite',
'PASSWORD': 'thepasswordyouchoose',
'HOST': 'localhost',
'PORT': '3306'
}
}
… and now the syncdb
command python manage.py syncdb
runs successfully.
- [Django]-Django Sessions
- [Django]-How to resolve "django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: foo" in Django 1.7?
- [Django]-Django – installing mysqlclient error: mysqlclient 1.3.13 or newer is required; you have 0.9.3
0👍
Also change the port number to ‘3307’if MySQl-python 64-bit in settings.py, Then only the connection happening in Windows and MySql 5.7 django.
‘3306’ for MySQl-python 32-bit
DATABASES = {
'default': {
'NAME': 'graphite',
'ENGINE': 'django.db.backends.mysql',
'USER': 'graphite',
'PASSWORD': 'thepasswordyouchoose',
'HOST': 'localhost',
'PORT': '3307'
}
}
- [Django]-AttributeError: 'Settings' object has no attribute 'ROOT_URLCONF'
- [Django]-Django: order_by multiple fields
- [Django]-How do I rename a Django project in PyCharm?
0👍
I use this config and it works.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'OPTIONS': {
'read_default_file': '/etc/my.cnf',
},
#'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
- [Django]-Celery Flower Security in Production
- [Django]-Convert string to html code in django template
- [Django]-Django import error – No module named core.management
0👍
It seems that all I have done is:
- drop my database
- drop the user
- re-create the user
- re-create the database
- grant to this user, flush privileges
and then it begin to work.
- [Django]-413 Request Entity Too Large nginx django
- [Django]-Django 1.9 deprecation warnings app_label
- [Django]-Filter Django objects where related object exists
0👍
I got the following error:
ModuleNotFoundError: No module named ‘MySQLdb’
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb
module. Did you install mysqlclient?
Solution # 01:
Verify that If you user has permission to access the database and perform the DDL & DML operations on it.
Solution # 02:
Changed the database configuration in settings.py file
From:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'db_name',
'USER': 'root'
}
}
To:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'db_name',
'USER': 'root',
'PASSWORD': 'root',
'HOST': 'localhost', # Or an IP Address that your DB is hosted on
'PORT': '3306',
}
}
And it started working.
- [Django]-Django model object with foreign key creation
- [Django]-What the difference between using Django redirect and HttpResponseRedirect?
- [Django]-Invalid block tag : 'endblock'. Did you forget to register or load this tag?
- [Django]-How can modify request.data in django REST framework
- [Django]-HTML Forms without actions
- [Django]-Django form resubmitted upon refresh
0👍
I ran into this issue while trying to connect to a remote DB after migrating it from my local host. I was able to clear this issue by deleting all the prior migrations, then running
python manage.py makemigrations
after that,
python manage.py migrate
solved my issue so I hope this helps.
- [Django]-Disable HTML escaping in Django's TextField
- [Django]-Target WSGI script cannot be loaded as Python module
- [Django]-Django one of 2 fields must not be null