Forums

Can't connect to MySQL server

Hi,

I can't run python manage.ph migrations from bach console. whatever I try it always raises this host issue:

File "/home/XYZ/.virtualenvs/msgl/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 227, in get_new_connection return Database.connect(conn_params) File "/home/XYZ/.virtualenvs/msgl/lib/python3.7/site-packages/MySQLdb/init.py", line 85, in Connect return Connection(*args, kwargs) File "/home/XYZ/.virtualenvs/msgl/lib/python3.7/site-packages/MySQLdb/connections.py", line 204, in init super(Connection, self).init(args, *kwargs2) django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on 'XYZ.mysql.pythonanywhere-services.com' (110)")

Thanks for your support in advance. Sezen E.

Are you sure you're using the correct hostname and username from your Databases tab and are you sure you have the correct Django settings as described here: http://help.pythonanywhere.com/pages/UsingMySQL/?

hi , I think so, This is what I have in my databases tab (I just replaced my user name with XYZ):

MySQL settings Connecting:

Use these settings in your web applications. Database host address: XYZ.mysql.pythonanywhere-services.com

Should I use something else?

thanks Sezen

No, but make sure that the other parts of the DATABASES settings entry are also correct.

thanks for the response Glenn.

Here is what I have in database settings, which looks good to me:

DATABASES = {

'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'xyz$abcdb',
    'USER':'xyz',
    'PASSWORD':'abcpassword',
    'HOST':'xyz.mysql.pythonanywhere-services.com',
    'PORT':'5432',
}

}

Why would it complain that it cannot connect to the database: 2003, "Can't connect to MySQL server on 'XYZ.mysql.pythonanywhere-services.com' (110)")

Is it physical access issue, I mean in networking layer or is it credentials issue preventing django to login to the database?

I can login to the database through the console successfully:

mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | xyz$default | | xyz$abcdb | +--------------------+ 3 rows in set (1.97 sec) mysql>

Thanks again in advance for your support.

Your port is wrong. Either use the correct default of 3306, or just leave it out entirely.

thanks glenn good catch, I had overlooked the port when I changed it from postgreSQL to mySQL. It works well after updating the port.

Thanks

import os

import sys

path='/home/sivaprasad/myproject'

if path not in sys path:

sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE']= 'myproject.settings'

from django.core.wsgi import get_wsgi_application

application = get_wsgi_application()

what is the error in this i can't understand here this code is used in wsgi.py fileand the error is syntax error in if class

This line is not correct:

if path not in sys path:

it should read:

if path not in sys.path: