PythonAnywhere Forums

Unknown MySQL server host

I tried connecting my database to my django app 1.10 and i followed the directions on how to set it up and connect it to my app but when i go to my bash console in my app directory and run python inspectdb or anything that has to do with the database i get

django.db.utils.OperationalError: (2005, "Unknown MySQL server host '<>' (0)")

I have my setting file as so

'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': '<your_username>$<your_database_name>',
    'USER': '<your_username>',
    'PASSWORD': '<your_mysql_password>',
    'HOST': '<>',

and i did replace the other fields with my username, database name, and password. What should i check and do to resolve this problem

That's very strange. What happens if you try to start a MySQL console from the "Databases" tab?

The consol connects to the database

Ah, got it -- your settings file isn't exactly what's being run by the code that generated the error message you pasted. If you look at the error message, it says you're trying to connect to -- it's missing the "-" between pythonanywhere and services. If you change your settings file so that it uses the correct hostname, it will work.

After changing the settings to adding a "-" i still got

(2005, "Unknown MySQL server host '<>' (0)")

Just to confirm- is this an error message that you are seeing from your webapp error logs?

no it is from the console when i try to migrate my models to the database

You have '<' and '>' around your host name. They are not part of a host name. Remove them. You may be making the same mistake with the other fields in your DATABASES dictionary.

glenn is 100% correct