Forums

What is the port for mysql in pythonanywhere?

How unkind it is , it doesn't show anything about port. Is there anyone knowing this?

3306, but check all of:

https://www.pythonanywhere.com/forums/topic/4634/

@LeeKyungMoon -- jgmdavies is right, it's the default port for MySQL, 3306. Most of the time you won't need to specify it -- most libraries, and the normal mysql client program, assume 3306 if you don't specify a port.

Although my code is running locally, I couldn't make it work here. I am having the following error regarding the database;

django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.

What is the exact code that you have for your DATABASES setting? (You should replace the MySQL password in any code you post with something like "XXXXX" for security, of course.)

My env info is in a JSON file. I am using the password I've set on the panel and other info provided for the MySQL connection.

{
  "FILENAME": "<json_file_name>.json",
  "SECRET_KEY": "<secret_key>",
  "DB_NAME": "<username>$<db_name>",
  "DB_USER": "<username>",
  "DB_PASSWORD": "<db_password>",
  "DB_HOST": "<db_host>",
  "DB_PORT": "3306",
  "ALLOWED_HOSTS": ["<allowed_host1>", "<allowed_host2>", "<allowed_host3>"]
}

In the settings.py, I have this config;

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': get_secret("DB_NAME"),
    'USER': get_secret("DB_USER"),
    'PASSWORD': get_secret("DB_PASSWORD"),
    'HOST': get_secret("DB_HOST"),
    'PORT': get_secret("DB_PORT"),
  }
}

At the moment, I am having an error related to my system environments, and it seems that this problem has been resolved after I made some changes. I am unsure whether these two issues are connected. The other issue is this.

Edit: I mean, the issues seem connected, but I think this MySQL-related one is not the root cause, and there is no problem with this configuration. The only problem is that the system environments cannot be read by the system right now.

The environment variables should be added on the wsgi level -- see this help page.

I changed my environment variable file type from JSON to .env and followed the link you provided, but I am getting the following error:

django.core.exceptions.ImproperlyConfigured: The ALLOWED_HOSTS setting must be a list or a tuple.

The parameter ALLOWED_HOSTS is like this in the .env file:

ALLOWED_HOSTS=.<username>.pythonanywhere.com,

There is a dot at the beginning and a comma at the end.

ALLOWED_HOSTS must me a list, and comma is not making a list. You need to use list() function or list literal [ ]

I made the change, and now I am getting a different error. I hope that at least this one has been solved now.