2

It's the first time I'm deploying a site using MySQL instead of SQLite3, so I'm quite new at this, after reading some documentation I found out that I have to change some files like this :

settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'my_site_db',
        'USER': 'username',
        'PASSWORD': 'password',
        'HOST': '?', #currently using pythonanywhere (not on localhost)           
        'PORT': '?',  
    }
}

manage.py

try:
    import pymysql
    pymysql.install_as_MySQLdb()
except:
    pass

(PyMySQL==0.7.10, Django 1.9, Python 3.5)

When I run the Bash Console using python manage.py migrate I get this error message :

django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' ([Errno 111] Connection refused)")

I thought it has something to do with the HOST and the PORT from the Database configurations, I don't know what I should add in these, does it have to do with MySQL, PythonAnywhere or even my own domain ? How can I resolve this problem and set up MySQL correctly with Django 3.5 ?

2 Answers 2

3

Check this guide. I used it to deploy my webapp.

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

What should I enter in <your_mysql_hostname>, the domain name ?
On the dashboard, your connection settings should be listed. To start using MySQL, you'll need to go to the MySQL tab on your dashboard, and set up a password. You'll also find the connection settings (host name, username) on that tab, as well as the ability to create new databases.
thanks, worked ! the article you provided is not ranked on the first results of SEO, so it was difficult to find something to help
0

You can use in this way

Username : johndoe

Database name : socialdatabase

Host : xyz.mysql.pythonanywhere-services.com

User : johndoe

Name : johndoe$socialdatabase

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'my_site_db', # Username$database name
    'USER': 'username', #Username:
    'PASSWORD': 'password',
    'HOST': '?', # Database host address           

}
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.