0
我在我的Django應用程序中有以下設置。爲什麼我無法連接到Django中的外部數據庫?
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'mydatabasename', # Or path to database file if using sqlite3.
'USER': 'davidfaux', # Not used with sqlite3.
'PASSWORD': 'mySecretPassword', # Not used with sqlite3.
'HOST': 'sql.externalhost.com', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
然而,當我使用manage.py
運行我的申請,我得到以下回溯。
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1045, "Access denied for user 'davidfaux'@'75.156.124.202' (using password: YES)")
75.156.124.202
是託管我的Django應用程序的專用服務器的IP地址。但是,我的數據庫位於settings.py中指定的外部服務器上。
爲什麼Django在專用服務器上尋找這個數據庫,而不是我指定的外部位置?
具體來說,您可能需要在MySQL中創建一個用戶'davidfaux @ 75.156.124.202'。 –
謝謝。我相信我的用戶/密碼組合。但是,我認爲你是對的。我沒有連接到外部數據庫。我不知道如何在MySQL中允許外部連接。我試圖在終端運行'mysql',但是我得到錯誤'ERROR 1045(28000):訪問被用戶'david'@'localhost'拒絕(使用密碼:NO)'。 – dangerChihuahua007
您將包含-p參數以使其詢問密碼:'mysql -h 75.156.124.202 -u davidfaux -p' – Lycha