Python Forum
Unable to connectDjango to mysql server
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to connectDjango to mysql server
#1
Hello All,
I have an error while connecting django to mysql server.
can any one help me with this?
it shows following error.

Output:
PS C:\Users\sures\Desktop\Project\1\healthinsurance> python manage.py runserver Watching for file changes with StatReloader Performing system checks... System check identified no issues (0 silenced). Exception in thread django-main-thread:
Error:
Traceback (most recent call last): File "C:\Users\sures\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\base\base.py", line 282, in ensure_connection self.connect() File "C:\Users\sures\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\asyncio.py", line 26, in inner return func(*args, **kwargs) File "C:\Users\sures\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\base\base.py", line 263, in connect self.connection = self.get_new_connection(conn_params) File "C:\Users\sures\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\asyncio.py", line 26, in inner return func(*args, **kwargs) File "C:\Users\sures\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\mysql\base.py", line 247, in get_new_connection connection = Database.connect(**conn_params) File "C:\Users\sures\AppData\Local\Programs\Python\Python310\lib\site-packages\MySQLdb\__init__.py", line 121, in Connect return Connection(*args, **kwargs) File "C:\Users\sures\AppData\Local\Programs\Python\Python310\lib\site-packages\MySQLdb\connections.py", line 195, in __init__ super().__init__(*args, **kwargs2) MySQLdb.OperationalError: (2002, "Can't connect to server on 'localhost' (10061)")
buran write May-20-2024, 07:16 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.

Attached Files

Thumbnail(s)
       
Reply
#2
which library are you using?

use: pip install mysqlclient

Ensure that the connection details in your Django settings are correct. In your settings.py file, check the DATABASES configuration:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'your_database_name',
        'USER': 'your_database_user',
        'PASSWORD': 'your_database_password',
        'HOST': 'localhost',
        'PORT': '3306',
    }
}
buran write May-20-2024, 07:15 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020