2

when I am trying to connect MySQL to python Django framework for accessing the database,and running the command python manage.py syncdb ,I get following errors. I have created database name mysite and changed into setting like this:

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

Traceback:

python manage.py syncdb

Traceback (most recent call last):
File "manage.py", line 10, in <module>
  execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py",  line 399, in execute_from_command_line
  utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute
  self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 242, in run_from_argv
  self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 285, in execute
  output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 415, in handle
  return self.handle_noargs(**options)
File "/usr/local/lib/python2.7/dist-  packages/django/core/management/commands/syncdb.py", line 57, in handle_noargs
  cursor = connection.cursor()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 160, in cursor
  cursor = self.make_debug_cursor(self._cursor())
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 132, in _cursor
  self.ensure_connection()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 127, in ensure_connection
  self.connect()
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 99, in __exit__
  six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 127, in ensure_connection
  self.connect()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 115, in connect
  self.connection = self.get_new_connection(conn_params)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py", line 435, in get_new_connection
  conn = Database.connect(**conn_params)
File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 81, in Connect
  return Connection(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 187, in __init__
  super(Connection, self).__init__(*args, **kwargs2)
  django.db.utils.OperationalError: (1045, "Access denied for user 'root'@'localhost'   (using password: YES)")
Marius Mucenicu
  • 1,257
  • 2
  • 12
  • 23
Ramesh KC
  • 560
  • 6
  • 21
  • 3
    is it not clear? Authentication fails for user root with the password you entered. – Odif Yltsaeb Jul 13 '14 at 05:40
  • When i type this command in my mysql prompt ;grant all privileges on *.* to root@localhost identified by 'password' with grant option; it shows this above result. – Ramesh KC Jul 13 '14 at 05:59
  • Are you sure you did not make any mistakes when entering password in settings.py? Could also check out this: http://dba.stackexchange.com/questions/10852/mysql-error-access-denied-for-user-alocalhost-using-password-yes – Odif Yltsaeb Jul 13 '14 at 06:04
  • when I type MySQL -u root -p in terminal and enter the password it says ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) – Ramesh KC Jul 13 '14 at 09:33
  • Man, we should be teaching you to google, i guess :P. Check out these links i found by googling:http://stackoverflow.com/questions/10299148/mysql-error-1045-28000-access-denied-for-user-billlocalhost-using-passw, http://ubuntuforums.org/showthread.php?t=1836919. And google yourself next time :). I barely even use mysql so i am not much of a help other than entering words into google search. – Odif Yltsaeb Jul 13 '14 at 09:56

2 Answers2

0

I had a similar error:

super(Connection, self).init(*args, **kwargs2) django.db.utils.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")

To solve it:

1) I removed the Password that I gave, but again I got error like this:

File "C:\Users\Rooman\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\mysql\operations.py", line 146, in last_executed_query query = query.encode(errors='replace') AttributeError: 'bytes' object has no attribute 'encode'

2) In the operations.py use decode instead of encode

    query = query.decode(errors='replace')

3) Finally run the commands:

    python manage.py makemigrations

    python manage.py migrate

    python manage.py runserver
ItsPete
  • 2,323
  • 3
  • 26
  • 34
0

you are providing a wrong username or password for the database

  • This post isn't an actual attempt at answering the question. Please note [StackOverflow doesn't work like a discussion forum](http://stackoverflow.com/tour), it is a Q&A site where every post is either a question or an answer to a question. Posts can also have [comments](http://stackoverflow.com/help/privileges/comment) - small sentences like this one - that can be used to critique or request clarification from an author. This should be either a comment or a [new question](http://stackoverflow.com/questions/ask) – ρяσѕρєя K Jan 06 '20 at 15:16