Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thousandlemons/c51f5c4ee1d79045ffa629237e835157 to your computer and use it in GitHub Desktop.
Save thousandlemons/c51f5c4ee1d79045ffa629237e835157 to your computer and use it in GitHub Desktop.
How to Connect Django to Remote MySQL

How to Connect Django to Remote MySQL

==[ONLY for Ubuntu]== Install libmysqlclient-dev

$ sudo apt-get install libmysqlclient-dev

Install mysqlclient.

$ sudo pip install mysqlclient

In settings.py, find the following block:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

Replace it with:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': '[database name]',
        'USER': '[database user with remote access privilege]',
        'PASSWORD': '[password]',
        'HOST': '[server ip address]',
        'PORT': '',
    }
}

On local OS X machine, open ~/.bash_profile, and add the following line into it:

export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/

Run django system check.

$ python manage.py check
@mobapps123
Copy link

super().init(*args, **kwargs2)
django.db.utils.OperationalError: (1045, "Access denied for user 'root'@'180.151.27.218' (using password: YES)")

@mobapps123
Copy link

mobapps123 commented Feb 2, 2023

error any one solve this problem

Linux os

@itsmehemant7
Copy link

@mobapps123 same issue...have you ever solved it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment