Search code examples
pythonmysqldjangodatabasepythonanywhere

Django PythonAnywhere (2003, "Can't connect to MySQL server (timed out)")


I'm trying to setup a Django project and I can't seem to connect to MySQL database made in PythonAnywhere.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'username$dbname',
        'USER': 'username',
        'PASSWORD': 'password',
        'HOST': 'username.mysql.pythonanywhere-services.com',
    }
}

I cant enter the database in the PythonAnywhere Bash with my user, host, name and password, but when i try to do it in django it appears as follows:

django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on 'username.mysql.pythonanywhere-services.com' (timed out)")


Solution

  • I couldn't fix this error. Installed MySQL Workbench and used localhost to run the database. After that, I was able to run the following code:

    DATABASES = {
         "default": {
             "ENGINE": "django.db.backends.mysql",
             "NAME": "Mysql",
             "USER": "admin",
             "PASSWORD": "password",
             "HOST": "127.0.0.1",
             "PORT": "3306",
        }
     }