简体   繁体   中英

Cannot connect MySQL database from django

I am trying to connect my MySql server from Django application , but whenever I am running the command python manage.py runserver it showing the error:

 File "/usr/local/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-linux-i686.egg/MySQLdb/connections.py", line 187, in __init__
 _mysql_exceptions.OperationalError: (1045, "Access denied for user 'user'@'localhost' (using password: NO)")

But my settings.py connection string is like :

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'django_personnel',       # Or path to database file if using sqlite3.
        'USER': 'root',                   # Not used with sqlite3.
        'PASSWORD': 'personnel',          # Not used with sqlite3.
        'HOST': '127.0.0.1', # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '3306',        # Set to empty string for default. Not used with sqlite3.
    }
} 

But I can easily connect the database from mysql shell :

 mysql -u root -ppersonnel django_personnel

Please guide me. Thanks in advance.

It seems that your current user is not having permissions to connect to DB. Re installing mysql will help and also

'HOST': '', 

'PORT': '', 

Leave these two fields empty

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM