Django的可以简单地通过设置连接到自己的MySQL服务器HOST
,并PORT
在settings.py
为""(空字符串):
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'dbname', # Or path to database file if using sqlite3.
'USER': 'root', # Not used with sqlite3.
'PASSWORD': 'root', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是如何使它能够连接另一台主机上的另一个数据库?假设我的机器192.168.1.33
和另一台要连接的机器192.168.1.34
都在同一个网络上.我试图将其设置为: …