Thomas.Q
Thomas.Q

Reputation: 477

Visit Heroku database and connect to local MySQL database

I have deployed a Django app in Heroku. It has some log-in function and data fill-in function. I want to know where is this information stored? How could I visit them?

In addition, in the Django app, I have add some function that connect to local MySQL database. But in the web deployed, the connection is refused. How could I deal with the problem? I am quite new in Heroku.

Here's the setting and view parts.

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    "bootstrap3",
    # my application
    "learning_logs.apps.LearningLogsConfig",
    "users.apps.UsersConfig",
    "django_forms_bootstrap",
    "ncbi_crawler",
)
DATABASES = {

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

    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'mall',
        'USER': 'rinka',
        'PASSWORD': 'xxxxx',
        'HOST': 'localhost',
        'PORT': '3306',
    }
}

This the view part.

def results(request):
    data=[]
    data1 = []
    owner = request.user
    owner = str(owner)
    db = MySQLdb.connect(user='root', db='crawling', passwd='xxxx', host='localhost')
    cursor = db.cursor()
    cursor.execute("SELECT search_content, pmid, journal, title, author, institute, abstract, article_info FROM result_split where username = '%s'" % (owner))
    data = cursor.fetchall()
    db.close()
    return render(request, "learning_logs/results.html", {"datas": data})

Upvotes: 0

Views: 299

Answers (1)

Sopan
Sopan

Reputation: 691

If you have deployed your app using git (git push heroku master) route then you can always connect from "heroku cli" by commands like heroku run python manage.py dbshell

Note - you won't be able to access your local database ( I assume you mean database on your laptop/desktop/machine whatever you use for your work) on Heroku instance.

Upvotes: 1

Related Questions